BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello,

I have a sample code below; I would like to calculate the age and ICU column percent of Sum_cost.  Is there a way to approach it? Thanks.

proc tabulate data=DataIn;
  var Cost_Sum;
  class age ICU;
  table (age ICU),(Cost_Sum) *(N mean std median p25 p75 sum);
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
Diamond | Level 26
Hi:
PROC TABULATE has quite a few "percent" statistics: ROWPCTN, ROWPCTSUM, PCTN, PCTSUM, COLPCTN, COLPCTSUM, etc. In addition, with PCTN and PCTSUM, you can ask for a custom denominator. I generally recommend using the built in statistics first to see whether there's one that suits your purposes. The TABULATE documentation has good examples of the percent statistics and how to request a custom denominator: https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0vdza4puzkcghn1j5xtqfb4sahr.htm and this is an excellent paper on the topic: https://support.sas.com/resources/papers/proceedings13/134-2013.pdf
Cynthia

View solution in original post

2 REPLIES 2
Cynthia_sas
Diamond | Level 26
Hi:
PROC TABULATE has quite a few "percent" statistics: ROWPCTN, ROWPCTSUM, PCTN, PCTSUM, COLPCTN, COLPCTSUM, etc. In addition, with PCTN and PCTSUM, you can ask for a custom denominator. I generally recommend using the built in statistics first to see whether there's one that suits your purposes. The TABULATE documentation has good examples of the percent statistics and how to request a custom denominator: https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0vdza4puzkcghn1j5xtqfb4sahr.htm and this is an excellent paper on the topic: https://support.sas.com/resources/papers/proceedings13/134-2013.pdf
Cynthia
donricardo
SAS Employee

Hi;

While this might be a bit over-simplified, perhaps it'll get you on your way:

data datain;
infile datalines;
input age icu cost_sum;
datalines;
17 1 10000
65 1 13250
44 2 6200
89 2 23000
;

proc format;
picture perc (round) low-high='09.99%' (multiplier=100);
run;

proc tabulate data=datain;
var cost_sum;
class age icu;
table(age icu),(cost_sum) * (n mean std median p25 p75 sum pctsum *f=perc.);
run;

I've used the pctsum keyword, one of Cynthia's suggestions, but often programmers have difficulty getting the needed '%' sign to appear.   To do this, you'll need to create your own format as I've done above, using a 'picture' statement instead of the usual value statement.    Here are some results using the make-believe dataset above:

donricardo_0-1672939424269.png

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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