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

I want to create a time series field between two dates where day is not mentioned, only month and year is mentioned.

 

For ex:-

Input:-

Start Date = 01/01/18     End Date = 31/12/20 

 

Output:-

01/18

02/18

03/18

    .

    .

    .

    .

    .

    .

10/20

11/20

12/20

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

First of all: never use two-digit years. After the Y2K scare, this should be an absolute given for anybody involved in the IT business.

Second, don't use date formats in a non-hierarchical order (MY in your case). Start with the most significant part (years). This helps in ordering when formatted values are used.

Third, use SAS date values when dates are involved. If you only need year/month, use the same day (day 1 in the following example) for each period.

data want;
period = '01jan2018'd;
do while (period le '01dec2020'd);
  output;
  period = intnx('month',period,1,'b');
end;
format period yymms7.;
run;

 

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

First of all: never use two-digit years. After the Y2K scare, this should be an absolute given for anybody involved in the IT business.

Second, don't use date formats in a non-hierarchical order (MY in your case). Start with the most significant part (years). This helps in ordering when formatted values are used.

Third, use SAS date values when dates are involved. If you only need year/month, use the same day (day 1 in the following example) for each period.

data want;
period = '01jan2018'd;
do while (period le '01dec2020'd);
  output;
  period = intnx('month',period,1,'b');
end;
format period yymms7.;
run;

 

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

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
  • 1 reply
  • 545 views
  • 2 likes
  • 2 in conversation