I need to add the outputs of proc means (5, 10, and 20 year averages) as new variables to an existing dataset (aug_yearly_weather) in the data step, but receive this error message:
ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase.
ERROR 557-185: Variable demo5 is not an object.
Below is my code:
/*find 5 year average of the number of days in August that were =>90 by year (2014 - 2018)*/
proc means data=demo5.aug_yearly_weather mean maxdec=0;
vars Max_Temp_90;
where date between '01aug2013'd and '31Aug2018'd; /* 5 year average includes 2014 - 2018, but must specify dates between 2013 and 2018*/
title "5 Year Average";
output out=demo5.aug_5_year_avg_90;
run;
/*find 10 year average of the number of days in August that were =>90 by year (2009 - 2018)*/
proc means data=demo5.aug_yearly_weather mean maxdec=0;
where date between '01aug2008'd and '31Aug2018'd; /* 10 year average includes 2009 - 2018, but must specify dates between 2008 and 2018*/
vars Max_Temp_90;
title "10 Year Average";
output out=demo5.aug_10_yr_avg_90;
run;
/*find 20 year average of the number of days in August that were =>90 by year (1999 - 2018)*/
proc means data=demo5.aug_yearly_weather mean maxdec=0;
vars Max_Temp_90; /* no need to specify date range because this includes the entire dataset */
title "20 Year Average";
output out=demo5.aug_20_yr_avg_90;
run;
/* Create the 5, 10, and 20 year averages variables within the dataset aug_yearly_weather */
data demo5.aug_yearly_weather1;
set demo5.aug_yearly_weather;
Five_year_avg_90 = demo5.aug_5_year_avg_90;
Ten_year_avg_90 = demo5.aug_10_year_avg_90;
Twenty_year_avg_90 = demo5.aug_20_year_avg_90;
run;
Below is the desired result:
Date | Max_Temp_90 | 5 Year Avg | 10 Year Avg | 20 Year Avg |
1999 | 25 | 24 | 26 | 25 |
2000 | 27 | 24 | 26 | 25 |
2001 | 25 | 24 | 26 | 25 |
2002 | 29 | 24 | 26 | 25 |
2003 | 27 | 24 | 26 | 25 |
2004 | 22 | 24 | 26 | 25 |
2005 | 19 | 24 | 26 | 25 |
2006 | 11 | 24 | 26 | 25 |
2007 | 27 | 24 | 26 | 25 |
2008 | 17 | 24 | 26 | 25 |
2009 | 29 | 24 | 26 | 25 |
2010 | 27 | 24 | 26 | 25 |
2011 | 30 | 24 | 26 | 25 |
2012 | 30 | 24 | 26 | 25 |
2013 | 26 | 24 | 26 | 25 |
2014 | 17 | 24 | 26 | 25 |
2015 | 31 | 24 | 26 | 25 |
2016 | 20 | 24 | 26 | 25 |
2017 | 25 | 24 | 26 | 25 |
2018 | 28 | 24 | 26 | 25 |
Thank you.
Thanks again!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.