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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.