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;

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 612 views
  • 2 likes
  • 2 in conversation