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'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,
	Radiology, 300,
	PF fee, 500,
;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26
proc sql;
    create table want as select
        pt_class
        ,charge
        ,100*charge/sum(charge) as percent
    from datain;
quit;
--
Paige Miller
ballardw
Super User

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;
ybz12003
Rhodochrosite | Level 12
I apologize for the confusion. I would like to get the percent = each PT_class / sum(Charge) , is it that clear?
japelin
Rhodochrosite | Level 12

how about this code?

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

Alternative solution:

 

proc freq data=datain;
    tables pt_class/out=want noprint;
    weight charge;
run;
--
Paige Miller

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1203 views
  • 6 likes
  • 4 in conversation