BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BernyOsuna
Obsidian | Level 7

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

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:

nlevels_shoes.png

 

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

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 5738 views
  • 1 like
  • 3 in conversation