Hi Guys
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;
%macro loop;
%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;
%end;
%mend; %loop;
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.
If you don't want to actually print the frequencies, just get the number of levels, then add the /NOPRINT option to the TABLES statement.
Hi:
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;
produces this:
Of course, you might not want to get the levels on the numeric variables, in which case you could change the dataset to have
tables _character_;
If you just wanted character variables.
Cynthia
If you don't want to actually print the frequencies, just get the number of levels, then add the /NOPRINT option to the TABLES statement.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.