Hi Everyone,
I have following dataset:
Date rel_day
2006-03-01 -1842
2006-03-02 -1841
2006-03-03 -1840
. .
. .
2011-03-07 0
. .
. .
2014-04-01 1111
2014-04-02 1112
I would like to create a column event_month where every 30 days from the event day would be a either +month or a -month. I have used the following codes to create +month or -month but only for a year.
sample code:
if relday>=-30 and relday<=-1 then event_month =-1;
if relday = 0 then event_month = 0;
if relday>=1 and relday<=30 then event_month = 1;
I need to create event_month for all dates in the dataset. Can someone please help? I have got many ISIN in the dataset.
Thanks.
data temp;
input Date:yymmdd10. rel_day;
cards;
2006-03-01 -1842
2006-03-02 -1841
2006-03-03 -1840
2011-03-07 0
2014-04-01 1111
2014-04-02 1112
;;;;
run;
data temp;
set temp(where=(rel_day eq 0));
event=date;
do while(not eof);
set temp end=eof;
relchk = event - date;
relmon = intck('MONTH',event,date);
output;
end;
stop;
format event date yymmdd10.;
run;
proc print;
run;
Your input sample and the required output sample is not clear. You can post a better and clearer one, and of course explaining the logic along with it
Hi Mark, as I indicated in my post, I want to create 30 days event window from +1 and -1 event day for all rel_day. Here is the sample conditions
if rel_day>=-60 and rel_day<=-31 then event_month =-2;
if rel_day>=-30 and rel_day<=-1 then event_month =-1;
if rel_day = 0 then event_month = 0;
if rel_day>=1 and rel_day<=30 then event_month = 1;
if rel_day>=31 and rel_day<=60 then event_month = 2;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.