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

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 🙂

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

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;
Reeza
Super User

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 🙂

 


 

Kurt_Bremser
Super User

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
;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 3 replies
  • 1115 views
  • 3 likes
  • 4 in conversation