/*****************************************************************/ /* Created by: Simon Freidin (Updated by: Michelle Summerfield) */ /* Purpose of the program: */ /* SAS program to create balanced responding person long */ /* longitudinal file using combined files. */ /*****************************************************************/ /* ********************************************************************* */ /* Section 1: locate datasets, get balanced cases, load renaming macro */ /* ********************************************************************* */ * (1.1) Specify the release and the version of the data used; %let release=180; %let version=180; %let maxwave=r; * (1.2) Location of datasets (edit to reflect your paths); libname hilda "X:\HILDA\Release &release.\files\SAS &version.c" access=readonly; * (1.3) Location of the output library; libname long 'C:\temp'; * Master file; data master; set hilda.master_&maxwave.&version.c (keep=xwaveid ahhrpid afstatus bhhrpid bfstatus chhrpid cfstatus dhhrpid dfstatus ehhrpid efstatus fhhrpid ffstatus ghhrpid gfstatus hhhrpid hfstatus ihhrpid ifstatus jhhrpid jfstatus khhrpid kfstatus lhhrpid lfstatus mhhrpid mfstatus nhhrpid nfstatus ohhrpid ofstatus phhrpid pfstatus qhhrpid qfstatus rhhrpid rfstatus); run; * Enumerated person file for each wave; data w1c; set hilda.combined_a&version.c; data w2c; set hilda.combined_b&version.c; data w3c; set hilda.combined_c&version.c; data w4c; set hilda.combined_d&version.c; data w5c; set hilda.combined_e&version.c; data w6c; set hilda.combined_f&version.c; data w7c; set hilda.combined_g&version.c; data w8c; set hilda.combined_h&version.c; data w9c; set hilda.combined_i&version.c; data w10c; set hilda.combined_j&version.c; data w11c; set hilda.combined_k&version.c; data w12c; set hilda.combined_l&version.c; data w13c; set hilda.combined_m&version.c; data w14c; set hilda.combined_n&version.c; data w15c; set hilda.combined_o&version.c; data w16c; set hilda.combined_p&version.c; data w17c; set hilda.combined_q&version.c; data w18c; set hilda.combined_r&version.c; run; * (1.4) Identify cases responding in all waves from the master file; * status codes: 1=face to face interview, 2=telephone interview; data masters (keep=xwaveid ahhrpid bhhrpid chhrpid dhhrpid ehhrpid fhhrpid ghhrpid hhhrpid ihhrpid jhhrpid khhrpid lhhrpid mhhrpid nhhrpid ohhrpid phhrpid qhhrpid rhhrpid); set master; if afstatus in (1,2) and bfstatus in (1,2) and cfstatus in (1,2) and dfstatus in (1,2) and efstatus in (1,2) and ffstatus in (1,2) and gfstatus in (1,2) and hfstatus in (1,2) and ifstatus in (1,2) and jfstatus in (1,2) and kfstatus in (1,2) and lfstatus in (1,2) and mfstatus in (1,2) and nfstatus in (1,2) and ofstatus in (1,2) and pfstatus in (1,2) and qfstatus in (1,2) and rfstatus in (1,2); run; * (1.5) Macro to rename variables, dropping first character of variable name,; * ID's are not renamed; * Writes a sas program to 'c:\temp', alter path if no c:\temp, also alter paths in %include statements; %macro rename (ds); data ren; set &ds; if _n_=1; proc transpose data=ren out=ren2;var _all_; data ren3; file 'c:\temp\rencmds.sas'; set ren2 end=eof; if _n_=1 then put " rename"; if _name_ not in ("XWAVEID","xwaveid", "ahhrhid","ahhrpid","bhhrpid","bhhrhid","chhrpid","chhrhid","dhhrpid","dhhrhid","ehhrhid","ehhrpid","fhhrhid","fhhrpid","ghhrhid","ghhrpid", "hhhrhid","hhhrpid","ihhrhid","ihhrpid","jhhrhid","jhhrpid","khhrhid","khhrpid","lhhrhid","lhhrpid","mhhrhid","mhhrpid","nhhrhid","nhhrpid", "ohhrhid","ohhrpid","phhrhid","phhrpid","qhhrhid","qhhrpid","rhhrhid","rhhrpid") then do; _name2_=_name_ || '=' || substr(_name_,2); put " " _name2_; end; if eof then put " ;"; run; %mend; /* **************************************************************** */ /* Section 2: create "long" responding person longitudinal file */ /* **************************************************************** */ * (2.1) Rename waves. Run macro and then include generated rename; * command file. Keep only those records in selected master file.; %macro ren; %do i=1 %to 18; %rename(w&i.c); data longcw&i.; set w&i.c; %include 'c:\temp\rencmds.sas'; proc sort data=longcw&i.; by xwaveid; proc sort data=masters; by xwaveid; data longcw&i.; merge masters(in=a) longcw&i.; by xwaveid; if a; run; %end; %mend; %ren; * (2.2) Put datasets together to create the long longitudinal responding; * person file, and add a year variable.; data longc; set longcw1 (in=w1) longcw2 (in=w2) longcw3 (in=w3) longcw4 (in=w4) longcw5 (in=w5) longcw6 (in=w6) longcw7 (in=w7) longcw8 (in=w8) longcw9 (in=w9) longcw10 (in=w10) longcw11 (in=w11) longcw12 (in=w12) longcw13 (in=w13) longcw14 (in=w14) longcw15 (in=w15) longcw16 (in=w16) longcw17 (in=w17) longcw18 (in=w18); * Create year; year=0; if (w1=1) then year=2001; if (w2=1) then year=2002; if (w3=1) then year=2003; if (w4=1) then year=2004; if (w5=1) then year=2005; if (w6=1) then year=2006; if (w7=1) then year=2007; if (w8=1) then year=2008; if (w9=1) then year=2009; if (w10=1) then year=2010; if (w11=1) then year=2011; if (w12=1) then year=2012; if (w13=1) then year=2013; if (w14=1) then year=2014; if (w15=1) then year=2015; if (w16=1) then year=2016; if (w17=1) then year=2017; if (w18=1) then year=2018; run; proc freq data = longc; table year; run; * (2.3) Save permanent dataset; data long.longc; set longc; run; * check the contents of the data; proc contents varnum data=long.longc; run; /* Supplementary programme to add longitudinal weights variables for Responding and Enumerated Persons specifically to be used in a balanced file of 18 waves. */ data weights; set hilda.Combined_&maxwave.&version.c; keep xwaveid &maxwave.lnwtrp &maxwave.lnwte; rename &maxwave.lnwtrp=lnwtrp &maxwave.lnwte=lnwte; run; data longc; set long.longc; drop lnwte lnwtrp; run; proc sort data=weights; by xwaveid; proc sort data=longc; by xwaveid; data long.longfinal; merge longc (in=inlong) weights; by xwaveid; if inlong; run; data test; set long.longfinal; keep xwaveid year lnwte lnwtrp; run; proc sort data=test; by year; proc means; var lnwtrp; by year; run;