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 such that there is only one entry for each month and the day in that entry is the last day of that specific month.

 

For ex:-

Input:-

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

 

Output:-

31/01/18

28/02/18

31/03/18

30/04/18

    .

    .

    .

    .

    .

    .

31/10/20

30/11/20

31/12/20

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Use the intnx() function to calculate your end-of-period values:

cur_date = intnx('month',start_date,0,'e');
do while (cur_date le end_date);
  output;
  cur_date = intnx('month',cur_date,1,'e');
end;

It is, of course, assumed that start_date and end_date contain SAS date values.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Use the intnx() function to calculate your end-of-period values:

cur_date = intnx('month',start_date,0,'e');
do while (cur_date le end_date);
  output;
  cur_date = intnx('month',cur_date,1,'e');
end;

It is, of course, assumed that start_date and end_date contain SAS date values.

kelxxx
Quartz | Level 8
options yearcutoff=2000;
 
%let indate=01/01/18;
%let outmon=12/18;

data toto;
sdate=input("&indate",ddmmyy8.);
emon=input("01/&outmon",ddmmyy8.);
edate=intnx ('month',emon,0,'E');
days=edate-sdate;
do i=0 to days;
datest=sdate+i;
output;
end;
format datest ddmmyy8.;
keep datest;
run;

Hi,

it is not optimal but it works

have a nice day.

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
  • 2 replies
  • 890 views
  • 0 likes
  • 3 in conversation