BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pinkyc
Calcite | Level 5

I have input data like this:

Pat_ID     Discharge_Date     Paid

AA                                           55.00

AA                                            0.00

AA          01/01/2012             -180.00

AA          04/01/2012             44.00

AA                                             37.00

AA                                             54.00

AA                                             0.00

BB                                             -200

BB          09/23/2012                   0.00

BB                                                54.00

I need to sum Paid by two ways, just grouping by Pat_ID and alternately by Discharge_Date and Pat_ID (so only the ones with not blank discharge dates are summed).  I know I can just create a sub-table with If Discharge_Date NE '' and sum the remaining Pat_ID's but was wondering if there's a way to do it in one step, more or less?  I also have 1580312 observations so I wonder if a proc sql method is better than the data step and sum.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I agree with Reeza. With an output data set from proc summary there will be a variable _type_ that describes the combinations of the class variables.

Proc summary data=have;

     class Pat_id Discharge_date;

     var paid;

     output out=want sum=;

run;

for example.

By default you well get a sum for 1) all records 2) each Pat_id 3) each Discharge_date and 4) each unique combination of Pat_id and Discharge_date.

View solution in original post

2 REPLIES 2
Reeza
Super User

I would recommend proc means/univariate/summary, especially since you can calculate sub-totals without an additional step.

Look into the CLASS, WAYS and TYPE statement in proc means.

ballardw
Super User

I agree with Reeza. With an output data set from proc summary there will be a variable _type_ that describes the combinations of the class variables.

Proc summary data=have;

     class Pat_id Discharge_date;

     var paid;

     output out=want sum=;

run;

for example.

By default you well get a sum for 1) all records 2) each Pat_id 3) each Discharge_date and 4) each unique combination of Pat_id and Discharge_date.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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