Hey guys,
I am trying to form portfolios on month T by looking back characteristics on month T-1.
This is the code I have written (It may appear very convoluted to you, because I'm new to SAS).
DATA Crsp;
SET Rawcrsp;
REFYEAR=PUT(DATE,YEAR.);
REFMONTH=PUT(DATE,MONTH.);
REFDATE= PUT(DATE,YYMMn.);
LENGTH PORTFOLIOYEAR $4.;
PORTFOLIOYEAR=REFYEAR;
LENGTH PORTFOLIOMONTH $2.;
PORTFOLIOMONTH=REFMONTH+1;
IF PORTFOLIOMONTH=13 THEN PORTFOLIOMONTH=1;
IF PORTFOLIOMONTH=13 THEN PORTFOLIOYEAR=REFYEAR+1;
LENGTH PORTFOLIODATE $6.;
PORTFOLIODATE=REFDATE;
RUN;
I have tabbed the 2 lines of code that I'm having trouble with.
Because December (12) will determine the portfolio in Jan (1). However, I am unsure how can I adjust the year so that it becomes the next year i.e. 200712 will determine a portfolio in 200801.
The other problem I have is how can I merge the columns PORTFOLIOYEAR AND PORTFOLIOMONTH to give me PORTFOLIODATE.
The reason is because I have written a long code following this (And only realised that I overlooked the Dec and Jan issue today). And the PORTFOLIODATE is crucial, if not the rest of my codes need to be edited.
Thanks guys. Appreciate the help!