BookmarkSubscribeRSS Feed
lin39
Obsidian | Level 7

Hi all, 

 

I need some help with Proc Tabulate!  I hope you can help me because I'm pulling my hair out.

 

I need to generate the table in the exact format as below:

SAS proc tab question1.JPG

 

I can only figure out some of it.  Below is my code:

proc tabulate data=data.ads  FORMAT=9.0 order=formatted;
var FEMALE LATINO_FLAG AGE_25_OLDER HSGPA BESTSAT;
CLASS DIRECT_ADMIT;
table DIRECT_ADMIT ='' *(sum Mean*f=PERCENT9.1), FEMALE LATINO_FLAG AGE_25_OLDER
/ ROW=FLOAT RTS=22 MISSTEXT='-' ;
KEYWORD all / style=[bordertopcolor=black bordertopwidth=1 bordertopstyle=double font_weight=bold fontstyle=italic];
run;

 

Since I can't share the data, I will use sashelp.shoes as an example:

proc tabulate data=sashelp.shoes;  
  where region in ('Asia', 'Canada') and product in ('Boot', 'Slipper');
  class product region;
  var sales returns stores inventory;
  table region * (sum mean),
        sales returns inventory stores;
run;

 

I'm able to achieve something like below (see screen cap), but I need to add:

- total column N

- total row N

- merged column heading 

- means columns at the end

SAS proc tab question2.JPG

Any help would be appreciated! Thank you!

1 REPLY 1
ballardw
Super User

Proc tabulate really doesn't do crossed statistics in a single table: row with mean or sum and column of n for example. To stack vertical statistics as you show the sum and mean would have to remain in the row dimension as you show

 

If you need output that looks exactly like your output it may be possible with the Report Writing Interface which would require using other steps to summarize the data before display.

 

If you were willing to accept the statistics all in column (  sum beside % instead of sum above % tabulate might be possible but would likely require some restructuring of your data.

 

For tabulate to do a grouped header as you show you would want one variable as a class variable that has values (or formatted values) of Male Latino and "Older than 25" similar to use of Product here:

proc tabulate data=sashelp.shoes;  
  where region in ('Asia', 'Canada') and product in ('Boot', 'Slipper');
  class product region;
  var sales returns stores inventory;
  table region * (sum mean),
        product*(sales returns inventory stores);
run;

Means as a column won't cross with sum and mean as row.

 

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
  • 1 reply
  • 6646 views
  • 2 likes
  • 2 in conversation