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!
If appropriate for your scenario, I would take a look at the intnx function.
If appropriate for your scenario, I would take a look at the intnx function.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.