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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 471 views
  • 6 likes
  • 4 in conversation