BookmarkSubscribeRSS Feed
Anita_n
Pyrite | Level 9

Dear all, 

I have a table that looks like this: 

 

drug period visit number_of_patients percentage N_Percentage
A period 1 1 5 16,67% 5(16,67%)
B period 2 1 10 33,33% 10(33,33%)
C period 3 2 12 50,00% 12(50,00%)
D period 1 2 3 12,50% 3(12,50%)
E period 2 3 15 35,71% 15(35,71%)
A period 3 3 20 47,61% 20(47,61%)
B period 1 3 7 16,67% 7(16,67%)
C period 2 4 5 35,71% 5(35,71%)
D period 3 4 9 64,28% 9(64,28%)
E period 1 5 10 76,92% 10(76,92%)
A period 2 5 3 23,08% 3(23,08%)
B period 3 1 8 26,67% 8(26,67%)
C period 1 1 7 23,33% 7(23,33%)
D period 2 2 7 29,17% 7(29,17%)
E period 3 2 2 8,33% 2(8,33%)

 

I wish to include the percentages (that means var should be number_of_patients and percentage or replace both with N_percentage) to the table. I already have the number of patients in there but I wish to add the percentages. This is calculated per visit. Here is my code any help:

proc tabulate data=have format=6.0 style=[font_size=5pt just=c fontstyle=italic borderwidth=0 cellpadding=0 foreground=dimgray];
class drug period visit / order=data style=[textalign=center ] missing;
  classlev drug period visit/ style=[background=white font_weight=bold font_size=5pt foreground=dimgray cellpadding=2];
   var  number_of_patients/;
   keyword all sum /style=[background=white font_weight=bold font_size=5pt foreground=dimgray];

  table ( drug=' '*all=' '*([style=[background=white foreground=dimgray font_weight=bold font_size=5pt]]))*(number_of_patients=' '), 
   sum=' '*period=''*visit=' ' / row=float nocontinued indent=1 rts=2  misstext=[label=" " ] 
   style=[cellpadding=3 font_size=5pt foreground=dimgray] 
   box=[label=' ' style=[background=white foreground=dimgray font_weight=bold font_size=5pt ]];
run;
 

 

1 REPLY 1
Kathryn_SAS
SAS Employee

Try the following revised code:

proc tabulate data=have format=6.0 
style=[font_size=5pt just=c fontstyle=italic borderwidth=0 cellpadding=0 
foreground=dimgray];
class drug period visit / order=data style=[textalign=center ] missing;
classlev drug period visit/ style=[background=white font_weight=bold font_size=5pt 
foreground=dimgray cellpadding=2];
var number_of_patients/;
keyword all sum /style=[background=white font_weight=bold font_size=5pt 
foreground=dimgray];
table drug=' '*period=' ', visit*number_of_patients=' '*(sum=' ' colpctsum=' '*f=8.1);
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1 reply
  • 744 views
  • 0 likes
  • 2 in conversation