%macro recode_absorb_dispute(varlist); %let nv=1; %let nxtv=%scan(&varlist,&nv); %do %while (%length(&nxtv)>0); array &nxtv.raw_[*] %listyrv(&nxtv,begy=1999); array &nxtv.e_[*] %listyrv(&nxtv.e,begy=1999); &nxtv = .; do i=1 to dim(&nxtv.raw_); if inyr_[i]=1 then do; &nxtv.now=.; /* recode and absorbing*/ if &nxtv.raw_[i] in (1,5) then &nxtv.now=(&nxtv.raw_[i]=1); else if &nxtv.raw_[i]=8 then &nxtv.now=.D; else if &nxtv.raw_[i]=9 then &nxtv.now=.R; else &nxtv.now=.M; if &nxtv = 1 and &nxtv.now = 0 then do; do j = 1 to (i-1); if inyr_[j] = 1 then &nxtv.e_[j] = 0; end; &nxtv = 0; end; &nxtv=max(&nxtv,&nxtv.now); &nxtv.e_[i]=&nxtv; end; end; %let nv=%eval(&nv+1); %let nxtv=%scan(&varlist,&nv); %end; %mend; %macro recode_absorb(varlist); %let nv=1; %let nxtv=%scan(&varlist,&nv); %do %while (%length(&nxtv)>0); array &nxtv.raw_[*] %listyrv(&nxtv,begy=1999); array &nxtv.e_[*] %listyrv(&nxtv.e,begy=1999); &nxtv = .; do i=1 to dim(&nxtv.raw_); if inyr_[i]=1 then do; &nxtv.now=.; /* recode and absorbing*/ if &nxtv.raw_[i] in (1,5) then &nxtv.now=(&nxtv.raw_[i]=1); else if &nxtv.raw_[i]=8 then &nxtv.now=.D; else if &nxtv.raw_[i]=9 then &nxtv.now=.R; else &nxtv.now=.M; &nxtv=max(&nxtv,&nxtv.now); &nxtv.e_[i]=&nxtv; end; end; %let nv=%eval(&nv+1); %let nxtv=%scan(&varlist,&nv); %end; %mend; %macro fill_missing(dis); /* fill forward if ever is equal to 1 */ do i = 2 to dim(&dis._); if &dis._[i] = . and &dis._[i-1] = 1 then do; &dis._[i] = 1; &dis._imp_[i] = 1; end; end; /* fill backward if ever is equal to 0 */ do i = dim(&dis._)-1 to 1 by -1; if &dis._[i] = . and &dis._[i+1] = 0 then do; &dis._[i] = 0; &dis._imp_[i] = 1; end; end; /* else set to 0 if missing */ do i = 1 to dim(&dis._); if &dis._[i] = . then do; &dis._[i] = 0; &dis._miss_[i] = 1; end; end; %mend;