I have the following table
ID | group | race | gender | ethnicity |
1 | A | white | female | hispanic |
2 | A | white | female | not hispanic |
3 | A | black | male | unknown |
6 | A | unknown | female | hispanic |
4 | B | asian | male | not hispanic |
5 | B | black | female | not hispanic |
I would like to do proc tabulate by 'group' that has total n per column and percentage per column
something like this:
A | B | ||
N | 4 | 2 | |
race | white | 2 (50%) | |
black | 1 (25%) | 1 (50%) | |
asian | 1 (50%) | ||
unknown | 1 (25%) | ||
gender | female | 3 (75%) | 1 (50%) |
male | 1 (25%) | 1 (50%) | |
ethnicity | Hispanic | 2 (50%) | |
not Hispanic | 1 (25%) | 2 (100%) | |
unknown | 1 (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;
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;
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: