/* Macro to create variables - takes condition and age as input, returns dummy variable For this, we will prefer the individual's own response. If that is missing, then we will use a proxy */ %macro onset(dis,age); &dis.&age=.M; /* Fill in the onset age dummy variable */ /* Favor own response */ do i = 1 to dim(&dis.age_) while (missing(&dis.&age)); if 0 < &dis.age_[i] <= &age and resp_[i] = 1 then &dis.&age = 1; else if &age < &dis.age_[i] <= 120 and resp_[i] = 1 then &dis.&age = 0; end; /* If still missing, use proxy */ do i = 1 to dim(&dis.age_) while (missing(&dis.&age)); if 0 < &dis.age_[i] <= &age and resp_[i] = 5 then &dis.&age = 1; else if &age < &dis.age_[i] <= 120 and resp_[i] = 5 then &dis.&age = 0; end; /* Fill in the zeroes for all others */ if &dis.&age = .M then &dis.&age = 0; %mend; /* Macro to calculate age of onset - takes stem of condition and age as input, returns age of onset */ %macro calc_onset(dis,begy,endy); /* Arrays we need */ array &dis.days_[*] %listyrv(&dis.days,begy=&begy,endy=&endy) ; array &dis.mnth_[*] %listyrv(&dis.mnth,begy=&begy,endy=&endy) ; array &dis.week_[*] %listyrv(&dis.week,begy=&begy,endy=&endy) ; array &dis.year_[*] %listyrv(&dis.year,begy=&begy,endy=&endy) ; array &dis.yrscalc_[*] %listyrv(&dis.yrs,begy=&begy,endy=&endy); array &dis.agecalc_[*] %listyrv(&dis.age,begy=1999,endy=2003); do i = 1 to dim(&dis.agecalc_); /* Zero out missings */ if &dis.days_[i] > 97 then &dis.days_[i] = 0; if &dis.mnth_[i] > 97 then &dis.mnth_[i] = 0; if &dis.week_[i] > 97 then &dis.week_[i] = 0; if &dis.year_[i] > 97 then &dis.year_[i] = 0 ; /* Calculate age of onset */ /* Initialize to 0 */ &dis.yrscalc_[i] = 0; &dis.agecalc_[i] = .; &dis.yrscalc_[i] = &dis.year_[i] + (&dis.week_[i]/52) + (&dis.mnth_[i]/12) + (&dis.days_[i]/365); if &dis.yrscalc_[i] > 0 then do; &dis.agecalc_[i] = floor(agecalc_[i] - &dis.yrscalc_[i]); end; end; %mend;