BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Reeza
Super User

@mikeed wrote:

For each ID, I'd would like to add up all the VALUES, from MONTH 1 to MONTH 12, for an annual VALUE.

Then I would like to find summary statistics of annual VALUE for each ID.

 

Perhaps this explains it better and it can't be accomplished in a single procedure, and that's my problem?


Yes, this is a two step problem so you can simply apply your proc twice. 

The first time you're summing for the totals and in the second you're generating your summary statistics of the total value. 

 

You can modify the statistics you get and the summary based on the statistics you specify in the PROC MEANS/SUMMARY statements. 

You've been provided with multiple samples on how to run it for one, so you should be able to expand it to two sets of data. 

But regardless, here's one way:

 

Screen Shot 2018-04-14 at 12.30.32 PM.png

 

Screen Shot 2018-04-14 at 12.30.52 PM.png

 

PaigeMiller
Diamond | Level 26

But you don't need two runs of PROC MEANS or PROC SUMMARY to do this.

 

You can do it in a single run of PROC SUMMARY by removing the NWAY option, and then you get annual totals for each ID value, and the total across ALL ID values.

--
Paige Miller
Reeza
Super User

The summary statistics wouldn't reflect the annual total though, it would reflect the distribution of the monthly values, not the annual total.

 


@PaigeMiller wrote:

But you don't need two runs of PROC MEANS or PROC SUMMARY to do this.

 

You can do it in a single run of PROC SUMMARY by removing the NWAY option, and then you get annual totals for each ID value, and the total across ALL ID values.


 

PaigeMiller
Diamond | Level 26

The mean when _TYPE_=0 is the mean of all the data. It is the annual total. It does not "reflect the distribution of monthly values".

--
Paige Miller
Reeza
Super User

It's the mean of the monthly values, not the annual values, so its on a different scale. 

If you don't sum the monthly values first, TYPE=_0_ would still be on a monthly scale. 

 

Original question:

I would like to determine mean, median, etc. for a yearly (annual) amount

 

 

I can only think of SQL that would enable it to run in a single step, but since you have a subquery it's not really a single step in my view.

 

/*Different solution, that does it all in one step or seems like it*/
proc sql;
create table want_one_step as
select mean(annual_total) as avg, median(annual_total) as med, std(annual_total) as std
from (select sum(value) as annual_total from have group by id);
quit;
PaigeMiller
Diamond | Level 26

You're correct! I missed that.

--
Paige Miller

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
  • 20 replies
  • 1631 views
  • 3 likes
  • 4 in conversation