Updated
Hi! Suppose I have dataset as followings
ID SEX RACE AGE
1 F Non-hispanic White 5-15
2 M Asian/Other 5-15
3 M Asian/Other 15-20
4 F Hispanic 15-20
5 M Hispanic 15-30
6 M Non-hispanic Black 25-30
I want to create a table as following
| 5-15 | 15-20 | 25-30 |
Sex |
|
|
|
Male | 50% | 66.6% | 100% |
Female | 50% | 33.3% | 0 |
Race |
|
|
|
Non-Hispanic White | 50% | 0 | 0 |
Non-Hispanic Black | 0 | 0 | 100% |
Hispanic | 0 | 66.6% | 0 |
Asian/Other | 50% | 33.3% | 0 |
I know how to use proc sql without sub-section age group but is there a way to aggregate all age sections in one step? Thanks!
Hi,
Please try this.
proc freq data=have order=data;
table sex*age/norow nocum nofreq nopercent ;
run;
Thank you! I just updated my question. This problem is after running your code there is still a "total N" column and row. I need to generate all percentage tables using all variables with age, so my output need to be a dataset or table for future modification.
A report table could look something like:
proc tabulate data=have; class age sex race ; table sex race , age=''*colpctn='' /misstext='0' ; run;
add other categorical variables to the class and table.
Note that this will only work if all records have values for all of the variables as tabulate by default excludes records with any missing values for the variables on a class statement OR add /missing to the Class statement to get missing treated as a category.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.