%macro addchg(v,lbl,chg=1,pctchg=1,years=1990 2000,genkeep=0); %*--take a root variable name in parm v and looks for vars &v_1990 and &v_2000. It will typically generate attrib and assignment statements to calculate Chg&v_1990_2000 and PctChg&v_1990_2000. This will permit us to generate these extra variables "on the fly". --*; %local vnow vthen vchg vpctchg; %local cury prevy; %let cury=%scan(&years,2); %let prevy=%scan(&years,1); %local chgsfx; %let chgsfx=_&prevy._&cury; %local new2keep; %let vnow=&v._&cury; %let vthen=&v._&prevy; %let vchg=Chg&v&chgsfx; %let vpctchg=Pct&vchg; %if &chg %then %do; %let new2keep=&vchg; attrib &vchg label="Change in &lbl &prevy - &cury" length=5; %end; &vchg = &vnow - &vthen; %if &pctchg %then %do; %let new2keep=&new2keep &vpctchg; attrib &vpctchg label="% Change in &lbl &prevy - &cury" length=4 format=6.1; if &vthen then &vpctchg = 100*&vchg / &vthen; %end; %if &genkeep %then %str( keep &new2keep; ); %mend addchg;