BookmarkSubscribeRSS Feed
sasmaverick
Obsidian | Level 7

I have a proc freq step as follows:

 

proc freq data=test;

tables v1 v2/out=test_out;

run;

 

I want the proc freq outputs to be saved in a separate dataset like v1.sas, v2.sas. The step that I have above creates a dataset for only the last variable (v2).

 

Please help.

 

Regards

 

 

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why do you want the output to many tables, that really isn't very efficient either here or for future programming.  Create one output dataset and use V1*V2 to get variables for each of the by groups, per:

http://support.sas.com/documentation/cdl/en/procstat/63104/HTML/default/viewer.htm#procstat_freq_sec...

 

You can then apply by group processing, or where clause out the required information.

sasmaverick
Obsidian | Level 7
I am trying to get frequency and percentage for each of the variables
independent of the other variables. Will a cross tab give me the same?

##- Please type your reply above this line. Simple formatting, no
attachments. -##
RW9
Diamond | Level 26 RW9
Diamond | Level 26

It should do, I have no test data to run it on myself, and don't use freq that much so can't think off the top of my head.  Try it and see what it gives you (or post test data).

Astounding
PROC Star

The simple solution creates multiple output data sets:

 

proc freq data=test;

tables v1 / out=v1_out;

tables v2 / out=v2_out;

run;

 

If you have hundreds of variables, this can be automated with macro language. 

 

There also may be ODS-based solutions.

Reeza
Super User

Use the ODS table. 

 

Proc freq data=have;
Table v1 v2;
ODS output onewayfreqs = want;
Run;

Here's an example to generate a nicely formatted table:

https://gist.github.com/statgeek/e0903d269d4a71316a4e

 

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