Hi everyone, I have a data set with about 100 variables and each of them has a different format because the codes in the variables are different. Problem: I don't know in advance how many variables I have to report on and each variable needs its related format. So if I have to query 25 variables, I have to apply 25 formats in my final output. I have a solution that works and I reproduced it partially below Let's assume that ALLSTATES is my large file and and I have to work on the subset called myfile. I wrote a macro based on if statements to assign each formats but this solution has a cost: an extra file is created at each if statement.So if have 60 variables, I will get 60 extra files. Is there a better way to do this and to avoid to get so many files? DATA ALLSTATES; CANADIAN="ON"; NORTH_E="NJ"; WEST_C="WA"; output; CANADIAN="QC"; NORTH_E="NY"; WEST_C="CA"; output; CANADIAN="MB"; NORTH_E="VE"; WEST_C="NE"; output; run; proc format ; VALUE $CAN (NOTSORTED) "ON"="ONTARIO" "QC"="QUEBEC" "MB"="MANITOBA"; run; proc format ; VALUE $NORTHE (NOTSORTED) "NJ"="NEWJERSEY" "NY"="NEWYORK" "VE"="VERMONT"; run; proc format ; VALUE $WEST (NOTSORTED) "WA"="WASHINGTON" "CA"="CALIFORNIA" "NE"="NEVADA"; run; DATA myfile ; set ALLSTATES; drop west_c; run; %macro formatmyvars(ds); %local dsid ; %let dsid = %sysfunc(open(&ds)); %if %sysfunc(varnum(&dsid, CANADIAN)) > 0 %then %do; data myfile2; set myfile; newv_CANADIAN=put(CANADIAN,$CAN.); run; %end; %else %do; data myfile2; set myfile;run; %end; %if %sysfunc(varnum(&dsid, NORTH_E)) > 0 %then %do; data myfile3; set myfile2; newv_NORTH_E=put(NORTH_E,$NORTHE.); run; %end; %else %do; data myfile3; set myfile2;run; %end; /*and so on*/ %mend formatmyvars; %formatmyvars(myfile );
... View more