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-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!

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.

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