BookmarkSubscribeRSS Feed
cbatzi01
Calcite | Level 5

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

3 REPLIES 3
mkeintz
PROC Star
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.
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Reeza
Super User

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. 

Ksharp
Super User
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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 1431 views
  • 0 likes
  • 4 in conversation