* Macro to rename transposed columns;
* Maps transposed columns back to an associated ID variable.;
* Calculate data driven number of factors for array processing;
data _null_;
retain N 0;
set nobs end=last;
call symput('IDvar'||trim(left(_N_)),compress(IDvar));
if last then call symput('N',trim(left(_N_)));
run;
* The default prefix for transposed variables is COL.;
* Replace COL with your own prefix where appropriate. ;
* Rename variables using a data step;
%macro mapID(dsetin=,dsetout=,prefix=COL,IDvar=&&IDvar&mapIDLoop);
%do mapIDLoop = 1 %to &N;
data &dsetout.;
set &dsetin.;
rename &prefix.&mapIDLoop = &prefix.&&IDvar&mapIDLoop;
run;
%end;
%mend mapID;
* Rename variables using a procedure.;
* Use this option when modifying indexed datasets.;
%macro mapID2(lib=,dset=,prefix=COL,IDvar=&&IDvar&mapIDLoop);
%do factorLoop = 1 %to &N;
options nolabel;
proc datasets lib=&lib. NOlist;
modify &dset..;
rename COL&factorLoop = &prefix._&&IDvar&mapIDLoop;
run;
%end;
%mend mapID2;
Recent Comments