* Marriage to Divorce; * Identify those people who changed from married to divorced in NLS data (mature women cohort); * Also record the NLS wave and the year where the change was recorded; * Marriage status varibles: R0002400 R0133700 R0205100 R0288200 R0308300 R0367600 R0455600 R0491300 R0661400 R0666600 R0721700 R0869900 R0997700 R1290700 R1664710 R3507200 R4278200 R5447500 R6516200; * Years of the survey: 1967 1971 1972 1974 1976 1977 1979 1981 1982 1984 1986 1987 1989 1992 1995 1997 1999 2001 2003; libname y "y:\sas\arrays"; libname library (y); *Initial look at the data; proc freq data=y.nlswomen; tables R0002400 R0133700 R0205100 R0288200 R0308300 R0367600 R0455600 R0491300 R0661400 R0666600 R0721700 R0869900 R0997700 R1290700 R1664710 R3507200 R4278200 R5447500 R6516200; run; * A problem with comparing these variables across years is that the categories change. An easy solution is to recode 1 -> 2 in all of these variables; *One approach to recoding; data new; set y.nlswomen; if R0002400 eq 2 then R0002400 =1; if R0133700 eq 2 then R0133700 =1; if R0205100 eq 2 then R0205100 =1; * etc etc etc; * This gives you the correct results, but it is tedious to type, bulky to debug, and there happens to be a better way; run; proc freq data=new; tables R0002400 R0133700 R0205100; run; *Using an array to do repetitive recoding; data new1; set y.nlswomen; array recodes{5} R0002400 R0133700 R0205100 R0288200 R0308300; * define an array; do i=1 to 5; if recodes{i}=2 then recodes{i}=1; * use the array; end; run; proc freq data=new1; tables R0002400 R0133700 R0205100 R0288200 R0308300; run; *Extend this to include more variables; data new2; set y.nlswomen; array recodes{*} R0002400 R0133700 R0205100 R0288200 R0308300 R0367600 R0455600 R0491300 R0661400 R0666600 R0721700 R0869900 R0997700 R1290700 R1664710 R3507200 R4278200 R5447500 R6516200; *You don't need to count the variables; do i=1 to dim(recodes); * Now you use dim() to bound the loop; if recodes{i}=2 then recodes{i}=1; end; drop i; * You don't need to keep i, do you?; run; *Using an array to create new variables for the recodes; data new3; set y.nlswomen; array original{*} R0002400 R0133700 R0205100 R0288200 R0308300 R0367600 R0455600 R0491300 R0661400 R0666600 R0721700 R0869900 R0997700 R1290700 R1664710 R3507200 R4278200 R5447500 R6516200; array mstatus{19}; * Create 19 new variables, mstatus1 - mstatus19; /*array mstatus{*} mstatus1 - mstatus19;*/ *same thing; do i=1 to dim(original); if original{i}=2 then mstatus{i}=1; else mstatus{i} = original{i}; end; drop i; run; proc freq data=new3; tables mstatus1-mstatus19; run;