BookmarkSubscribeRSS Feed
Justin9
Obsidian | Level 7

Please can someone tell me how to save the unique values that are shown from a proc freq of a variable in the 'Results' tab and save them as a new dataset with just that one variable and all of the values? The proc freq of my variable shows that there are over 100 different values.

5 REPLIES 5
PaigeMiller
Diamond | Level 26

You use the OUT= option of the TABLES statement in PROC FREQ.

--
Paige Miller
Justin9
Obsidian | Level 7
Thanks! Is there a way to exclude the 'count' and 'percent' columns in the output (from the out= option, not the proc freq), so that I am left with just the values of the variable? Is there also a way to exclude the missing row in the output?
PaigeMiller
Diamond | Level 26

... so that I am left with just the values of the variable

You can use the NLEVELS option in the PROC FREQ statement if you just want the levels and not the count or percent. And ODS output to get it into a data set.

 

 

 

--
Paige Miller
Reeza
Super User

@Justin9 wrote:
Thanks! Is there a way to exclude the 'count' and 'percent' columns in the output (from the out= option, not the proc freq), so that I am left with just the values of the variable? 

Yes, you can use data set options in the output such as DROP/KEEP.

 

tables sex / out=want (drop = percent);

@Justin9 wrote:
 Is there also a way to exclude the missing row in the output?

Yes, you can use data set options in the output such as WHERE.

 

tables age / out=want (where = not missing(age));

 

Putting it all together:

data class;
set sashelp.class;
if age=14 then call missing(age);
run;


proc freq data=class noprint;
tables age / out=want (where=(not missing(age)) 
                       drop = percent  )  ;
run;

proc print data=want;
run;
tarheel13
Rhodochrosite | Level 12
If you just want the unique values, you could do select distinct var from dataset in proc sql.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 5 replies
  • 1873 views
  • 2 likes
  • 4 in conversation