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

Hi Madam/Sir,

 

I want to construct the standard deviation of quarterly sales over the the preceding 16 quarters using the attached file ("songdata"). 

GVKEYDATADATEFYEARQFQTRsaleq
1004198502281984350.939
1004198505311984460.128
1004198508311985153.836
1004198511301985261.04
1004198602281985364.541
1004198605311985468.595
1004198608311986166.376
1004198611301986275.907
1004198702281986371.83
1004198705311986484.079
1004198708311987174.543
1004198711301987281.31
1004198802291987392.951
10041988053119874100.858
1004198808311988190.007
10041988113019882100.645

 

I try to find the relevant code, but it is hard to revise this code. Any help will be highly appreciated.

data a2; set a1;
by gvkey;
array t {16} _temporary_;
if first.gvkey then call missing(of t{*});
do fy=sum(lag(fyearq),1) to fyearq-1;
t{1+mod(fy,16)}=.;
stdsale=std(of t{*});
run;

 

Thank you

Joon1

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data want;
array p{0:15} _temporary_;
set have; 
by gvkey;

if first.gvkey then call missing(of p{*});

p{mod(_n_,16)} = saleq;

stdsales = std( of p(*));

run;

For this approach to work you must have continuous time periods. If your time periods are not continuous and you're missing quarters this approach will not work. 

https://gist.github.com/statgeek/27e23c015eae7953eff2

 

View solution in original post

2 REPLIES 2
Reeza
Super User
data want;
array p{0:15} _temporary_;
set have; 
by gvkey;

if first.gvkey then call missing(of p{*});

p{mod(_n_,16)} = saleq;

stdsales = std( of p(*));

run;

For this approach to work you must have continuous time periods. If your time periods are not continuous and you're missing quarters this approach will not work. 

https://gist.github.com/statgeek/27e23c015eae7953eff2

 

joon1
Quartz | Level 8

Thank you so much. I greatly appreciate for your help.

Joon1

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
  • 2 replies
  • 406 views
  • 0 likes
  • 2 in conversation