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 stock as 
 select cusip,std(price), invertal(Filing_Date-10biz day to Filing_Date+10biz day) as with_in_std 
  from rvol
   group by cusip, interval(Filing_Date);
quit;

 

1.PNG

 

Hello!

 

Yeah... I want to calculate std(price) by setting intervals or ranges. I know the code to calculate std(price) set by id, year, or both and several combinations. This time, I try to calculate std(price) by intervals. However, as long as I know there is no code like interval() so wonder how can I obtain std(price) from a certain date to another certain date(In my case, the are std(price) between both ends of 10 business days away from the filing date). As I have the dates on the first row(trading days only), I think I can tack price variations by these trading days. 

 

So.. the key is... how to connect a filing date to both ends. I am trying to various possible codes now by searching for this community.

So far, I have not found and assume there is none similar. (If I find, I will link it.)

 

If you know some solutions, please share with me!

 

I appreciate your comments!

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Try this variation on @PaigeMiller 's code:

 

proc summary data=rvol nway;
where intck("day", namesDate, filingDate) between -10 and 10;
class cusip filingDate;
var price;
output out=want std=priceStd;
run;

this assumes that your dates are SAS date values.

(untested)

PG

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Something like this:

 

data two;
    set one;
    if filing_date-10<names_date<filing_date+10 then interval=1;
    else interval=0;
run;

proc summary nway data=two;
    class filing_date;
    var price;
    weight interval;
    output out=want std=price_std;
run;
--
Paige Miller
JKCho
Pyrite | Level 9

Thank you, PaigeMiller!

 

I used your code and found it worked well.

While I think this can be a solution, I would like to ask one more. There are some companies(cusip) having the same filing dates and need to separate them. 

 

Could you give me more hints on how to separate firms(cusip) having the same filing dates? I have been thinking about it and continue to do so... but still no clue.

 

I first put cusip and filing_date in the CLASS statement so I could have the combination but... it did mean # of cusip multiplied by # of the filing date.

 

Any suggestion is good!

 

Thank you!

PGStats
Opal | Level 21

Try this variation on @PaigeMiller 's code:

 

proc summary data=rvol nway;
where intck("day", namesDate, filingDate) between -10 and 10;
class cusip filingDate;
var price;
output out=want std=priceStd;
run;

this assumes that your dates are SAS date values.

(untested)

PG
JKCho
Pyrite | Level 9
Thank you PGStats!!
It works!
PaigeMiller
Diamond | Level 26

@JKCho wrote:

Thank you, PaigeMiller!

 

I used your code and found it worked well.

While I think this can be a solution, I would like to ask one more. There are some companies(cusip) having the same filing dates and need to separate them. 

 

Could you give me more hints on how to separate firms(cusip) having the same filing dates? I have been thinking about it and continue to do so... but still no clue.

 

I first put cusip and filing_date in the CLASS statement so I could have the combination but... it did mean # of cusip multiplied by # of the filing date.

 

Any suggestion is good!

 

Thank you!


That's the great thing about PROC SUMMARY. If you want this analysis for each combination of CUSIP and FILING_DATE (instead of by FILING_DATE but not CUSIP as in my original program), all you have to do is change the CLASS statement so that it contains both variable names.

--
Paige Miller
JKCho
Pyrite | Level 9
Oh... I got your point!
Thank you again!!!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1421 views
  • 3 likes
  • 3 in conversation