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

I need to create an incremental table in SAS. This table contains the first day of month and the final month day until today (every month needs to execute).It seems like this

  1. First day month Final month day
    01/01/2019 31/01/2019
    01/02/2019 28/02/2019
    01/03/2019 31/03/2019
    01/04/2019 30/04/2019
    01/05/2019 31/05/2019
    01/06/2019 30/06/2019
    01/07/2019 31/07/2019
    01/08/2019 31/08/2019
    01/09/2019 30/09/2019
    01/10/2019 31/10/2019
    01/11/2019 30/11/2019
    01/12/2019 31/12/2019
    01/01/2020 31/01/2020
    01/02/2020 29/02/2020
    01/03/2020 31/03/2020
    01/04/2020 30/04/2020
    01/05/2020 31/05/2020
    01/06/2020 30/06/2020
    01/07/2020 31/07/2020
    01/08/2020 31/08/2020
    01/09/2020 30/09/2020
    01/10/2020 31/10/2020

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

data want;
   first = '01jan2019'd;
   do while (1);
      last = intnx('month', first, 0, 'e');
      if last > today() then leave;
      output;
      first = last + 1;
   end;
   format first last ddmmyy10.;
run;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

You can use the INTNX function

 

data want;
    startmonth='01JAN2019'd;
    i=0;
	last_day_month=0;
    do until ( last_day_month>today());
        first_day_month=intnx('month',startmonth,i,'b');
        last_day_month=intnx('month',startmonth,i,'e');
        i=i+1;
		output;
    end;
    keep first_day_month last_day_month;
	format first_day_month last_day_month ddmmyys10.;
run;
--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

Try this

 

data want;
   first = '01jan2019'd;
   do while (1);
      last = intnx('month', first, 0, 'e');
      if last > today() then leave;
      output;
      first = last + 1;
   end;
   format first last ddmmyy10.;
run;
ballardw
Super User

@t34 wrote:

I need to create an incremental table in SAS. This table contains the first day of month and the final month day until today (every month needs to execute).It seems like this

  1. First day month Final month day
    01/01/2019 31/01/2019
    01/02/2019 28/02/2019
    01/03/2019 31/03/2019
    01/04/2019 30/04/2019
    01/05/2019 31/05/2019
    01/06/2019 30/06/2019
    01/07/2019 31/07/2019
    01/08/2019 31/08/2019
    01/09/2019 30/09/2019
    01/10/2019 31/10/2019
    01/11/2019 30/11/2019
    01/12/2019 31/12/2019
    01/01/2020 31/01/2020
    01/02/2020 29/02/2020
    01/03/2020 31/03/2020
    01/04/2020 30/04/2020
    01/05/2020 31/05/2020
    01/06/2020 30/06/2020
    01/07/2020 31/07/2020
    01/08/2020 31/08/2020
    01/09/2020 30/09/2020
    01/10/2020 31/10/2020

Thanks


Kind of missed a specified starting point. Possibly implied "from 01Jan2019" but really should state the starting value. SAS will work with dates back to the year 1518. So stating the start is somewhat important.

 

Just for fun, how exactly do you intend to use the resulting intervals?

t34
Obsidian | Level 7 t34
Obsidian | Level 7
Thanks a lot, I just want to start from 01Jan2019

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 4 replies
  • 1273 views
  • 3 likes
  • 4 in conversation