I have the following table
dataset#1: table1
patientid | group | age | male_gender | white_race |
1234 | placebo | 65 | 1 | 1 |
4564 | placebo | 45 | 1 | 0 |
5646 | treatment | 55 | 0 | 1 |
6544 | placebo | 67 | 1 | 1 |
2345 | treatment | 39 | 0 | 0 |
2343 | placebo | 47 | 0 | 0 |
I would like to create a following table
Treatment | Placebo | |
Male | 0/2 (0%) | 3/4 (75%) |
White | 1/2 (50%) | 2/4 (50%) |
I can use proc freq but I am unable to get the denominator for treatment and placebo
proc freq a.table1;
table group;
run;
proc freq data=have;
table male_gender*group;
table white_race*group;
run;
This gives you what you asked for, plus rows you didn't ask for, you can just ignore the rows you don't want. If it has to appear EXACTLY as you showed, then a little more programming is needed.
It is not clear if you actually want the numerator and denominator as well a percentage for your output
For 1/0 coded variables as implied by your male_gender and white_race values I think this should get you started.
data have; input patientid $ group :$10. age male_gender white_race ; datalines; 1234 placebo 65 1 1 4564 placebo 45 1 0 5646 treatment 55 0 1 6544 placebo 67 1 1 2345 treatment 39 0 0 2343 placebo 47 0 0 ; proc tabulate data=have; class group; var male_gender white_race; table male_gender white_race , group=' '* (n='Denominator' sum='Numerator'*f=best. mean='%'*f=percent8.0) ; run;
Add LABELS for your variables to get nicer output. By default for character variables the sort order for display is alphabetic. So if you want to force Treament to appear to the left of Placebo in the output something will need to be done and depending on the values may vary from table layout and data contents.
In this case you might want to sort the data by descending group values and use the /order=data on the class statement for group.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.