- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!!!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Replace
put(caldt,yymmn6.) as yymm
by
year(caldt) as year
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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).
Paige Miller