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

Hi everyone, 

 

Below I have data now for 2 firms. 

 

data now;
input ticker $ EventDate EvntMonth;
datalines;

AA 09262013 9
ADI 11192012 11
;
run;

 

I want to create data like this (below demonstration ignore the second firms and the other 4 years after the AA's event date). The row will be added to five years after the event date for EACH firm. Please help to show me how I can do that. I am appreciated your help!

 

 

data want;
input ticker $ EventDate EvntMonth RealMonth countmonth AccMonth;
datalines;
AA 09262013 092013 9 0 092013
AA 09262013 092013 10 1 102013
AA 09262013 092013 11 2 112013 
AA 09262013 092013 12 3 122013
AA 09262013 092013 1 4 012014
AA 09262013 092013 2 5 022014
AA 09262013 092013 3 6 032014
AA 09262013 092013 4 7 042014
AA 09262013 092013 5 8 022014
AA 09262013 092013 6 9 022014
AA 09262013 092013 7 10 022014
AA 09262013 092013 8 11 082014
AA 09262013 092013 9 12 022014
;
run;

I look for the solution and find that Reeza used macro do loop for increment months as follows:

 

%macro loop;

%do i=1 %to 12;

%let date=%sysfunc(intnx(month, %sysfunc(today()), &i.), date9.);

%put &date.;

%end;

%mend;

%loop;

But I do not know how to apply it to my case. Please help me! thank you so much!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ShiroAmada
Lapis Lazuli | Level 10

Try this

data want;
 set now;
 do Countmonth=0 to 12;
   EvntMonth =EventDate;
   AccMonth=intnx('month',EventDate,Countmonth);
   RealMonth =month(AccMonth);
   format EvntMonth AccMonth yymmn6. ;
   output;
 end;
run;
   

View solution in original post

2 REPLIES 2
ShiroAmada
Lapis Lazuli | Level 10

Try this

data want;
 set now;
 do Countmonth=0 to 12;
   EvntMonth =EventDate;
   AccMonth=intnx('month',EventDate,Countmonth);
   RealMonth =month(AccMonth);
   format EvntMonth AccMonth yymmn6. ;
   output;
 end;
run;
   
LucyDang
Obsidian | Level 7

Hi ShiroAmanda, I'm appreciated your quick response! This works perfectly in my case! 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 2966 views
  • 1 like
  • 2 in conversation