@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:
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.
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.
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".
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;
You're correct! I missed that.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.