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
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;
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.