Hi, I'd like to see a number of months left from the date to the end of the year.
I know to count month I can use intck('month', 'start', 'end', 'D') but how to get the "end" date when it's not given. I dont know how to pass the 'end' argument. Only what I got is the start date.
I would like to see:
date months
01JUN2019 7
01APR2020 9
Have a good day 🙂
data have;
input date :date9. ;* months;
format date date9.;
cards;
01JUN2019 7
01APR2020 9
;
data want;
set have;
Months=intck('mon',date,intnx('year',date,0,'e'))+1;
run;
data have;
input date :date9. ;* months;
format date date9.;
cards;
01JUN2019 7
01APR2020 9
;
data want;
set have;
Months=intck('mon',date,intnx('year',date,0,'e'))+1;
run;
You can find the end of the year with the following code:
year_end = intnx('year', today(), 0, 'e');
months = intck('month', date, year_end, 'D');
You can nest those if needed.
@PatrykSAS wrote:
Hi, I'd like to see a number of months left from the date to the end of the year.
I know to count month I can use intck('month', 'start', 'end', 'D') but how to get the "end" date when it's not given. I dont know how to pass the 'end' argument. Only what I got is the start date.
I would like to see:
date months
01JUN2019 7
01APR2020 9
Have a good day 🙂
Use intnx() to get year's end (actually the start of next year since you want the current month to be counted also):
data want;
input date :date9.;
months_left = intck('month',date,intnx('year',date,0,'e') + 1);
format date yymmddd10.;
datalines;
01JUN2019
01APR2020
;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.