Rhodochrosite | Level 12

## How to get the percent for the total charge column?

Hello,

I'm curious how to get the percent for the total amount of in the 'Charge' column.  Thanks.

``````data dataIN;
infile datalines dsd;
input PT_class : \$50.  Charge;
datalines;
ICU, 100,
Lab, 200,
PF fee, 500,
;``````
1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: How to get the percent for the total charge column?

ANY time you discuss percent, or other rates for that matter, you need to define what value is used for the numerator and what value is used for the denominator.

So since I don't see anything clearly labeled as "total charge" I have no confidence what a percentage would be with that data.

And do you want a data set, for further manipulation, or a report, for people to see?

A report might be:

```proc tabulate data=datain;
var charge;
class pt_class;
table pt_class,
charge*pctsum
;
run;```
5 REPLIES 5
Diamond | Level 26

## Re: How to get the percent for the total charge column?

``````proc sql;
create table want as select
pt_class
,charge
,100*charge/sum(charge) as percent
from datain;
quit;``````
--
Paige Miller
Super User

## Re: How to get the percent for the total charge column?

ANY time you discuss percent, or other rates for that matter, you need to define what value is used for the numerator and what value is used for the denominator.

So since I don't see anything clearly labeled as "total charge" I have no confidence what a percentage would be with that data.

And do you want a data set, for further manipulation, or a report, for people to see?

A report might be:

```proc tabulate data=datain;
var charge;
class pt_class;
table pt_class,
charge*pctsum
;
run;```
Rhodochrosite | Level 12

## Re: How to get the percent for the total charge column?

I apologize for the confusion. I would like to get the percent = each PT_class / sum(Charge) , is it that clear?
Rhodochrosite | Level 12

## Re: How to get the percent for the total charge column?

``````proc sql;
create table want as
select PT_class, Charge, round(charge/sum(Charge)*100,0.01) as perc
from dataIN
;
quit;``````
Diamond | Level 26

## Re: How to get the percent for the total charge column?

Alternative solution:

``````proc freq data=datain;
tables pt_class/out=want noprint;
weight charge;
run;``````
--
Paige Miller
Discussion stats
• 5 replies
• 471 views
• 6 likes
• 4 in conversation