Hi SAS users, I'm working on a macro where I'd like to 1) re-code values and 2)convert those values from character to numeric. As I have over 20 variables that require re-coding and convert, I'm hoping to use a macro to make it as efficient as possible. Thus far, I've only been able to figure out how to do one variable at a time within the data step. Any suggestions? Thanks! data have; input StudyID $1-2 CaseID $4-6 m2blue $8-12 q1green $14-18 k5orange $20-24; datalines; AA AA1 0-No 0-No 1-Yes BB BB1 0-No 0-No 0-No CC CC1 1-Yes 0-No 1-Yes DD DD1 0-No 1-Yes 1-Yes EE EE1 1-Yes 1-Yes 1-Yes FF FF1 0-No 0-No 0-No GG GG1 0-No 0-No 0-No HH HH1 0-No 1-Yes 0-No II II1 1-Yes 0-No 0-No JJ JJ1 1-Yes 0-No 1-Yes ;; run; data bugn; input vd $ 1-40; datalines; m2blue q1green k5orange ; run; data _null_; set bugn end=last; call symput('vd'||left(put(_n_,3.)),vd); if last then call symput('bugn',_n_); run; options mprint; %macro loop; %do i=1 %to &bugn; %let ti=%cmpres(&bug&i); data two; vd="&&vd&i"; run; %let vd=&&vd&i; data want; set have (rename=(&vd=&vd._old)); format &vd 1.; %do i=1 %to &bugn; if substr(&vd._old,1,1) = '0' then &vd=0; else if substr(&vd._old,1,1) = '1' then &vd=1; retain &vd; keep &vd; %end; run; %end; %mend loop; %loop;
... View more