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
Thanks
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;
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;
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;
@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
- 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/2020Thanks
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?
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.
Ready to level-up your skills? Choose your own adventure.