DATA Step, Macro, Functions and more

How do I format a table based on Proc Freq output

Reply
Occasional Contributor
Posts: 11

How do I format a table based on Proc Freq output

Hi, 

 

I have used proc freq on several variables cross referencing a year variable: 

 

Proc Freq data=have;

tables Var*year

run;

 

Instead of the standard proc freq output, which stacks Freq, Col Percent, Row percent, etc., I'd like to have a table that joins the freq and Col percent into a single cell (or at least appear that way visually).  Here is an example hand keyed from excel.  I'd like to have sas output it in the format I need, rather than reentering the sas output into excel each time.  

Gender20122013201420152016
Male25 (12.5%)50 (25%)75 (37.5%)90 (45%)100 (50%)
Female175 (87.5%)150 (75%)125 (62.5%)110 (55%)100 (50%)

 

Thanks!
Chris

Trusted Advisor
Posts: 1,022

Re: How do I format a table based on Proc Freq output

What you describe should be solved with

table var*year / norow nopercent;

which tells SAS to not print row percentages or global percentages, leaving only column percentages.
Super User
Posts: 19,855

Re: How do I format a table based on Proc Freq output

There isn't a default way to do this, you need to create some custom code to generate the table you want. 

 

Program it once in SAS, if you're interested in writing the code look up a Cynthia Zender Paper called creating complex reports. 

 

If you just wanr code, look up Summary tables in lexjansen.com, there are a lot of written papers on this topic. 

Super User
Posts: 10,044

Re: How do I format a table based on Proc Freq output

In order to create a complex report,
First PROC SQL, then PROC TRANSPOSE.

proc sql;
create table temp as
select sex,age,cats(count(*),'(',
put( count(*)/(select count(*) from sashelp.class where sex=a.sex) ,percent7.2),
 ')') as value
 from sashelp.class as a
  group by sex,age
;
quit;
proc transpose data=temp out=want prefix=age;
by sex;
var value;
id age;
run;
proc print noobs;run;

Ask a Question
Discussion stats
  • 3 replies
  • 208 views
  • 0 likes
  • 4 in conversation