proc sql;
create table snp1 as
select put(caldt,yymmn6.) as yymm, mean(SPINDX) as mean_price
from snp
group by calculated yymm
;
quit;
I think I am almost there.
My data set is monthly so... instead of having yymm6 I may need something to sum by year. I put some weird things like yyyyn6 and yes. it didn't work.
Could you tell me how can I get yearly average's' when using monthly data? I have months from 1964 to 2018 so.. there will be more than 50 yearly average!
Thank you!!!
proc summary data=snp nway;
class caldt;
format caldt year.;
var spindx;
output out=snp1(drop=_:) mean=mean_price;
run;
You could give proc summary a try.
Replace
put(caldt,yymmn6.) as yymm
by
year(caldt) as year
proc summary data=snp nway;
class caldt;
format caldt year.;
var spindx;
output out=snp1(drop=_:) mean=mean_price;
run;
You could give proc summary a try.
@JKCho wrote:
proc sql; create table snp1 as select put(caldt,yymmn6.) as yymm, mean(SPINDX) as mean_price from snp group by calculated yymm ; quit;
I think I am almost there.
My data set is monthly so... instead of having yymm6 I may need something to sum by year. I put some weird things like yyyyn6 and yes. it didn't work.
Could you tell me how can I get yearly average's' when using monthly data? I have months from 1964 to 2018 so.. there will be more than 50 yearly average!
Thank you!!!
Hello @JKCho — as we discussed in one of your other threads, your variable CALDT is already a SAS date value, and is formatted so it appears as 19840107; and so because it is a SAS date value, there is no need (and it is actually wrong) to use
put(caldt,yymmn6.)
As discussed in your other thread, and as apparent from the other answers in this thread, you simply need to use the YEAR function as shown by @Shmuel, and not the PUT function (or alternatively as shown by @andreas_lds you can use the YEAR. format).
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.