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
SAS Super FREQ
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
SAS Super FREQ
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

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 610 views
  • 4 likes
  • 3 in conversation