06-26-2018 09:55 PM
So this is the situation I have a bunch of tables that i need to bring all of their variables and pull all the different values they can hold so i made this
proc contents data=xxx out=yyy (keep=name); run;
proc sql noprint; select count(*) into : maxvar separated by 'anything' from yyy; quit;
%do i = 1 %to &maxvar.
data _null_; set yyy; if _n_ = &i. then call symput ("var", compress(name)); run;
proc freq data = yyy nlevels; tables &var. / noprint; run;
Im doing it one by one since there are some previous filters applied to the list of variables to pull their levels. If i do an out = zzz this will bring a list of all the values and their percentage, i dont need that i just need a dataset with the levels of the varariable so then i can concatenate them into a single dataset.
06-26-2018 10:34 PM
I'm not sure you need a macro process unless you want something more complicated than this. The name of the output object for NLEVELS is very sensibly named "NLEVELS" so you can use an ODS OUTPUT statement to get the NLEVELS for all the variables into 1 datastep with one PROC FREQ step:
ods output nlevels=work.nlev_all; proc freq data=sashelp.shoes nlevels; tables _all_; run; proc print data=work.nlev_all; run;
Of course, you might not want to get the levels on the numeric variables, in which case you could change the dataset to have
If you just wanted character variables.
Need further help from the community? Please ask a new question.