I have monthly data collected over two years. The datafiles have M# at the start of some of the variables, but not all of them (some have a different prefix, some have no prefix). I have successfully used the macro in this paper (http://support.sas.com/resources/papers/proceedings09/075-2009.pdf) to strip off the prefix using repeated runs of the macro to capture all of the variables that I need to have the prefix removed from. The problem is that this creates new variables that do not have the labels and formats that were assigned to the original variables. How can I modify this code to pull over the labels and formats as well? Code from Weng and Fung paper: %macro replaceprefix(dsn,dsnout,start,end,oldprefix,newprefix); data temp; set &dsn.; run; %LET ds=%SYSFUNC(OPEN(temp,i)); %let ol=%length(&oldprefix.); %do i=&start %to &end; %let dsvn&i=%SYSFUNC(VARNAME(&ds,&i)); %let l=%length(&&dsvn&i); %let vn&i=&newprefix.%SUBSTR(&&dsvn&i,&ol+1,%EVAL(&l-&ol)); %end; data &dsnout.; set temp; %do i=&start %to &end; &&vn&i=&&dsvn&i; drop &&dsvn&i; %end; %let rc=%SYSFUNC(CLOSE(&ds)); proc contents data=&dsnout. varnum; title 'Replacing Prefix on Selected variables '; run; %mend replaceprefix;
... View more