DATA Step, Macro, Functions and more

Storing Proc Freq Data in a table

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Storing Proc Freq Data in a table

Hi, 

 

I am writing several proc freq procedures and am wanting to store them output table in a file. I am specifying that I only want the frequency and the column percentage. However, when I open the table that is created (newdata) the percentage stored is the total frequency percentage not the column percentage. What am I doing wrong? The results tab shows what I am wanting in the frequency table. 

 

Here is my code.......

 

proc freq data=mydata;

tables varA*varB/ out=newdata nopercent nocum norow;

run;

 

But the table "newdata" is showing 

 

varA    varB    Frequency Count       Percent of Total Frequency 

 

Not

 

varA    varB    Frequency Count       Column Percentage

 


Accepted Solutions
Solution
‎12-15-2015 11:34 AM
Super User
Posts: 17,912

Re: Storing Proc Freq Data in a table

Change the drop statement to reflect the variables you want to drop, they are space separated, not comma delimited.

 

(drop=pct_row percent)

View solution in original post


All Replies
Super User
Posts: 17,912

Re: Storing Proc Freq Data in a table

You need to add OUTPCT to add the pct columns to the output data set, check the docs for details.

This is a bit of a roundabout way to get what you want, but easy enough. Someone else may have a better answer Smiley Happy

 

proc freq data=sashelp.class;
table age*sex/out=want(drop=pct_row) outpct norow nocum;
run;

proc print data=want;
run;

 

 

 

Contributor
Posts: 24

Re: Storing Proc Freq Data in a table

This drops the row percentage. Thank you. How do I also get it to drop the percentage of frequency total? I tried adding pct_tabl but it did not work 

 

(drop=pct_row, pct_tabl)

Super User
Posts: 5,093

Re: Storing Proc Freq Data in a table

The variable name holding the total percent is PERCENT:

 

(drop=percent)

Solution
‎12-15-2015 11:34 AM
Super User
Posts: 17,912

Re: Storing Proc Freq Data in a table

Change the drop statement to reflect the variables you want to drop, they are space separated, not comma delimited.

 

(drop=pct_row percent)
Contributor
Posts: 24

Re: Storing Proc Freq Data in a table

Thank you

Super User
Posts: 10,538

Re: Storing Proc Freq Data in a table

If you want to use Proc Freq to generate multiple output sets from a single input dataset use multiple TABLE statements. Each table statement will only build one output data set.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 263 views
  • 0 likes
  • 4 in conversation