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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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