BookmarkSubscribeRSS Feed
pacman94
Calcite | Level 5

I have the following table

IDgroupracegenderethnicity
1Awhitefemalehispanic
2Awhitefemalenot hispanic
3Ablackmaleunknown
6Aunknownfemalehispanic
4Basianmalenot hispanic
5Bblackfemalenot hispanic

 

I would like to do proc tabulate by 'group' that has total n per column and percentage per column

 

something like this:

  AB
N 42
racewhite2 (50%) 
 black1 (25%)1 (50%)
 asian 1 (50%)
 unknown1 (25%) 
genderfemale3 (75%)1 (50%)
 male1 (25%)1 (50%)
ethnicityHispanic2 (50%) 
 not Hispanic1 (25%)2 (100%)
 unknown1 (25%) 

proc tabulate data=test format=8.2 out =test2;
class group;
table

race all, (race all)*(n*f=8. reppctn) / rts=10;

ethnic all, (ethnic all)*(n*f=8. reppctn) / rts=10;

gender all, (gender all)*(n*f=8. reppctn) / rts=10;

run;

 

 

 

2 REPLIES 2
ballardw
Super User

First, if you expect two statistics in a single "cell" that is not possible within Proc tabulate.

Second if you want this in a single report table then a table statement can have only one semicolon.

The way that you portray race, gender and ethnicity they would also have to be defined as class variables.

The Comma in a Proc Tabulate table statement separates dimensions, the * nests .

Proc tabulate will have ALL the rows of a column with the same statistic, or if the statistic is defined in the row dimension, all columns will have the statistic.

Since your "want" table does not show a summary row for any of race, gender, ethnic you do not want the "ALL" the way you were using it.

You can suppress labels for variables or statistics by using =' ' after the variable name or statistic.

 

Have you haven't looked you will find that the data set created by Proc Tabulate does not appear like the report results. It has one row per variable combination in each dimension and statistics.

 

This may get closer.

 

proc tabulate data=test format=8.2 out =test2;
class group race ethnic gender;
table All='N'   race ethnic gender,
      Group=' ' *(n=' '*f=8. pctn=' ') 
    / rts=10;


run;

 

 

Reeza
Super User
PROC FREQ can get you fairly close as well.

Here's another way of doing it. Run the example code, as is and verify it meets your needs. If it does, then modify it for your data set.

https://gist.github.com/statgeek/0c4aeec9053cf8050be18a03b842c1b9

Or consider trying this macro out:
https://communities.sas.com/t5/SAS-Communities-Library/Demographic-Table-and-Subgroup-Summary-Macro-...

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 498 views
  • 0 likes
  • 3 in conversation