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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 941 views
  • 0 likes
  • 4 in conversation