BookmarkSubscribeRSS Feed
radhikaa4
Calcite | Level 5

I have the following table

 

dataset#1: table1

patientidgroupagemale_genderwhite_race
1234placebo6511
4564placebo4510
5646treatment5501
6544placebo6711
2345treatment3900
2343placebo4700

 

I would like to create a following table

 TreatmentPlacebo
Male0/2 (0%)3/4 (75%)
White1/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;

2 REPLIES 2
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller
ballardw
Super User

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.

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
  • 369 views
  • 0 likes
  • 3 in conversation