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!
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;
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;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.