BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
awardell
Obsidian | Level 7

Hello! 

 

I am having trouble with stacking cross-tabulations from proc freq output for multiple variables across the same grouping variable. I want a table like the following: 

 

 

 

                              Test

variable

Category

Arm_1

Arm_2

Total

 

 

N=

N=

N=

 

 

 

 

 

sex

Female

 

 

 

 

Male

 

 

 

race

Black

 

 

 

 

white

 

 

 

 

Hispanic

 

 

 

 

I would like to essentially stack the PROC FREQ output for the sex*arm and race*arm cross tabulations into a single table. 

 

I have tried using

ods table CrossTabFreqs=freqout;

But that hasn't given me exactly what I wanted. I have been using the sashelp.class dataset to try to work through the setup with the age*sex and height * sex crosstabs, but was not able to achieve the format above. 

 

Any help is greatly appreciated. Thanks! 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

If I understand right then below should get you close to the layout you're after.

proc tabulate data=sashelp.cars(obs=10);
  class make type origin;
  keylabel n='N=' all='Total';
  table make type, (origin all)*n;
  ;
run;

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

If I understand right then below should get you close to the layout you're after.

proc tabulate data=sashelp.cars(obs=10);
  class make type origin;
  keylabel n='N=' all='Total';
  table make type, (origin all)*n;
  ;
run;
ballardw
Super User

I would suggest Proc Tabulate as well but provide a warning related to missing values on variables used for CLASS role: default behavior is that any class variable that is missing will exclude the entire observation from the table(s). There are some ways around this depending but need to see example data and the expected result to see if possible.

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 613 views
  • 2 likes
  • 3 in conversation