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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

If appropriate for your scenario, I would take a look at the intnx function.

Data never sleeps

View solution in original post

1 REPLY 1
LinusH
Tourmaline | Level 20

If appropriate for your scenario, I would take a look at the intnx function.

Data never sleeps

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 626 views
  • 0 likes
  • 2 in conversation