BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JKCho
Pyrite | Level 9

 

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!!!

 

1.PNG

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19
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.

View solution in original post

3 REPLIES 3
Shmuel
Garnet | Level 18

Replace 

put(caldt,yymmn6.) as yymm

 by

year(caldt) as year
andreas_lds
Jade | Level 19
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.

PaigeMiller
Diamond | Level 26

@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!!!

 

1.PNG

 


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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

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