Monthly Archives: January 2008

macro(s) to rename transposed variables

* 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;

defining emacs alias in MKS Toolkit

(Double slashes required. See MKS documentation for details.)
$ alias emacs='C:pathtobinrunemacs.exe'

proc transpose macro

* macro to make datasets wide rather than long;
%macro transpose(dsetin=,dsetout=,prefix=,by=,var=);
proc sort data=&dsetin.;
by &by.;
run;
proc transpose data=&dsetin. out=&dsetout. (drop=_name_) prefix=&prefix.;
by &by.;
var &var.;
run;
%mend transpose;