BookmarkSubscribeRSS Feed
Viveme789
Fluorite | Level 6

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!

4 REPLIES 4
stat_sas
Ammonite | Level 13

Hi,

 

Please try this.

 

proc freq data=have order=data;
table sex*age/norow nocum nofreq nopercent ;
run;

Viveme789
Fluorite | Level 6

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. 

ballardw
Super User

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.

Reeza
Super User
If this is for a report, consider using PROC TABULATE instead. You have more control over the output there, including percentages.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1886 views
  • 0 likes
  • 4 in conversation