BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Lapis Lazuli | Level 10

Guys, 

I'm trying to perform a simple task. 

i have a data set with many columns. Among them two columns named: "Start" and "End". 

They contain date: e.g:

 

          ID                 Start                       End

       00001        12/01/2020             15/01/2020

       00001        20/01/2020             25/01/2020

       00001        30/01/2020            01/02/2020

       00002        02/02/2020            05/02/2020

       00002        06/02/2020            03/03/2020

       00003        01/05/2020            31/12/2020

       00004        01/07/2020            01/08/2020 

      ............      .................             .....................

 

I simply would like to count row-wise the days in the intervals and the months in the intervals of time from Start to End. I tried: 

 

data want;
set myinput;
format start end mmddyy10.;
months_diff = intck('months', start, end);

days_diff = intck('days', start, end);
run;

 

But it fails. For sure I'm wrong. 

 

Can anyone help me please? Thank you in advance

 

 

 

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You need to use the names of valid intervals with the iNTCK() function.  MONTH and DAY can work with DATE values.  But MONTHS and DAYS will not be understood. 

 

Note that for MONTH it counts the number of month boundaries crossed, which might not be what you want if any of your dates are not the first of them month.  You might try setting the fourth parameter to the function to 'same'.

 

Note for days you can just subtract as DATE values are numbers of days.

months_diff = intck('month', start, end,'same');
days_diff = end - start;

PS Displaying date in DMY or MDY order will confuse 50% of your audience.  Does 10/12 mean October Twelfth or the Tenth of December?

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You need to use the names of valid intervals with the iNTCK() function.  MONTH and DAY can work with DATE values.  But MONTHS and DAYS will not be understood. 

 

Note that for MONTH it counts the number of month boundaries crossed, which might not be what you want if any of your dates are not the first of them month.  You might try setting the fourth parameter to the function to 'same'.

 

Note for days you can just subtract as DATE values are numbers of days.

months_diff = intck('month', start, end,'same');
days_diff = end - start;

PS Displaying date in DMY or MDY order will confuse 50% of your audience.  Does 10/12 mean October Twelfth or the Tenth of December?

NewUsrStat
Lapis Lazuli | Level 10

Thank you for help. it is what I received. The format is ddmmyy. So, 10/12 is December the 10th.

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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 879 views
  • 1 like
  • 2 in conversation