SAS Programming

DATA Step, Macro, Functions and more
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

HI!!!

 

I found a very close answer here: 

https://wrds-www.wharton.upenn.edu/pages/support/applications/event-studies/event-study-research-app...

 

But still... I wonder how can I get a monthly return from a specific date.

e.g. from July 13th to Aug 13.

If either or both dates are nontrading days, then select the next trading days. Since I have to have a month interval, the code used in the link that can only sets intervals instead of a certain period of time(like month and year) is not the right one.

 

I wonder how other CRSP users can get stock returns too.

If you use CRSP and know how to get month-long returns please share your knowledge.

 

Thank you,

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The first part will be starting with actual SAS date values. Do you have that yet?

I think that you want the INTNX function with the 'Same' option.

 

data example;
   do date='25Jan2020'd to '31JAN2020'd;
      newdate = intnx('month',date,1,'S');
      output;
   end;
   format date newdate date9.;
run;

I used dates from 2020 as it is a leap year. 29, 30 and 31 Jan all get advanced to 29 Feb.

If you use 2019 then 28, 29, 30 and 31 Jan all get advanced to 28 Feb.

View solution in original post

5 REPLIES 5
Astounding
PROC Star
Just to confirm then ...

For a starting date of Jan 28, 29, 30, or 31, the ending date will be Feb 28?
JKCho
Pyrite | Level 9
February can be either ending in 28th or 29th depending on the data. Still wondering I can make this kind of code. My intention is simple.

I want to know return a month later. But it is depending on the data(trading days) whether the date a month later is a trading day or not. If not, the date will be the next trading day.
JKCho
Pyrite | Level 9
I rather write another post so that you may understand better what I want to do. Thx though
ballardw
Super User

The first part will be starting with actual SAS date values. Do you have that yet?

I think that you want the INTNX function with the 'Same' option.

 

data example;
   do date='25Jan2020'd to '31JAN2020'd;
      newdate = intnx('month',date,1,'S');
      output;
   end;
   format date newdate date9.;
run;

I used dates from 2020 as it is a leap year. 29, 30 and 31 Jan all get advanced to 29 Feb.

If you use 2019 then 28, 29, 30 and 31 Jan all get advanced to 28 Feb.

JKCho
Pyrite | Level 9
Awwwwwwwwwwwwwwwwwwesome!
That is what I want!!
THX X 10000000000!!!!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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