/* macro invoked by extract_data.sas*/ %macro chron_cond(chronvar, agevar, answer, ageonset_cutoff, ageonset_cutoffvar); /* purpose: creates absorbing dummy for specific chronic condition of interest, the age of onset (first mention), and a dummy for whether the condition was present at a certain age. IMPORTANT!! The question in the survey on which this variable is based is open ended, so won't provide very reliable prevalence estimates arguments: (chronvar=apne, <- creates variables apnee11, apnee13, apnee15, apnee17 for each survey year Note the 'e' for "ever" variable agevar=sleepapneaage, <- age of onset for each survey year (sleepapneaage11 etc) answer=23, <- the answer number that is given for a specific condition (see codebook) ageonset_cutoff=25, <- creates dummy variable for cutoff before age 25 ageonset_cutoffvar=sleepapnea) <- dummy variable will be called sleepapnea25 NB: Don't name chronvar and ageonset_cutoffvar the same (in case the survey year and age cutoff are the same, e.g. 2017 and age 17) */ /* "ever" variable denotes whether had condition in the past */ array &chronvar.e_[*] %listyrv(&chronvar.e,begy=2011); /* age variable denotes the first age mentioned, carrying it forward */ array &agevar._[*] %listyrv(&agevar.,begy=2011); &chronvar.=.; &agevar.=.; &ageonset_cutoffvar.&ageonset_cutoff.=0; do i=1 to dim(chron_); &chronvar.now=.; &agevar.now=.; if chron_[i]=1 then do; /* yes to whether other chronic condition was diagnosed */ /* check whether it's the specific chronic condition of interest */ if chroncond_[i]=&answer. then do; &chronvar.now=1; /* if match, pull the age of onset for that condition */ if (1 <= chroncondage_[i] <= 120) then &agevar.now=chroncondage_[i]; else if chroncondage_[i]=995 then &agevar.now=0; else if chroncondage_[i]=998 then &agevar.now=.D; else if chroncondage_[i]=998 then &agevar.now=.R; else &agevar.now=.M; end; /* the following two lines are for a 'yes' response for chronic condition, but without answer for which one */ else if chroncond_[i]=98 then &chronvar.now=.D; else if chroncond_[i]=99 then &chronvar.now=.R; end; /* answered no/DK/refused to whether other chronic condition was diagnosed */ else if chron_[i]=5 then &chronvar.now=0; else if chron_[i]=8 then &chronvar.now=.D; else if chron_[i]=9 then &chronvar.now=.R; else &chronvar.now=.M; /* carry over dummy values of 1 for the condition to following years (absorbing) */ &chronvar.=max(&chronvar.,&chronvar.now); &chronvar.e_[i]=&chronvar.; /* carry over the first mentioned age for that condition to following years */ if i=1 then &agevar._[i]=&agevar.now; else if &agevar._[i-1] then &agevar._[i]=&agevar._[i-1]; else &agevar._[i]=&agevar.now; /* create dummy variable if person had condition before a certain age */ if (0 < &agevar._[i] <= &ageonset_cutoff.) then &ageonset_cutoffvar.&ageonset_cutoff.=1; end; drop &chronvar. &chronvar.now &agevar. &agevar.now i; %mend chron_cond;