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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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