Just to be clear, it is not possible to _directly_ change a variable's type. You must go through some intermediary, whether it be a differently named variable or a text file, to convert. The general approach would be: 1. Actually convert them. 2. Obtain the old labels/names and order. 3. Apply the labels/names and order. Step 1 can be done a number of different ways; something like data want; set have; newvar1 = input(oldvar1,best12.); rename newvar1=oldvar1; drop oldvar1; run; accomplishes this. You could macro-ize this: %macro convert(var); &var._new = input(&var.,best12.); rename &var._new = &var.; drop &var.; %mend convert; Then you could include some method of fixing the labels. Here's an example. This may not work perfectly because you may have to break up the two long macro variables (&namelist and &convertlist) if they are more than 20k characters long - but you can use varnum to filter that easily like you suggest (do first 500 then next 500 etc.) Important is that &namelist contains ALL variables, and &convertlist contains the ones you are converting. data class; set sashelp.class; newage=put(age,3.); newheight=put(height,3.); newweight=put(weight,3.); rename newage=age newheight=height newweight=weight ; label newage='Age of Person' newheight='Height of Person' newweight='Weight of Person' ; drop age height weight; run; %macro convert(var); &var._new = input(&var.,best12.); rename &var._new = &var.; drop &var.; callstr=cats("label &var.='",vlabel(&var.),"';"); if _n_ = 1 then call execute(callstr); %mend convert; proc sql; select name into :namelist separated by ' ' from dictionary.columns where libname='WORK' and memname='CLASS' order by varnum; select cats('%convert(',name,')') into :convertlist separated by ' ' from dictionary.columns where libname='WORK' and memname='CLASS' and upcase(name) in ('AGE','HEIGHT','WEIGHT'); quit; data class_n; set class end=end; if _n_ = 1 then do; call execute ("data class_n_f; retain &namelist.; set class_n;"); end; &convertlist; if end then do; call execute("run;"); end; run;
... View more