BookmarkSubscribeRSS Feed
xxformat_com
Barite | Level 11

 

data one;    
    _start='01JAN2017'd; _end='15JAN2017'd; dif=(15.5*30/31)/360;     output;
    _start='16JAN2017'd; _end='31JAN2017'd; dif=(15.5*30/31)/360;     output;
    _start='01FEB2017'd; _end='14FEB2017'd; dif=(13.06666*30/28)/360; output;
    _start='15FEB2017'd; _end='28FEB2017'd; dif=(14.93333*30/28)/360; output;
    _start='01MAR2017'd; _end='31MAR2017'd; dif=(31*30/31)/360;       output;
    _start='01APR2017'd; _end='11APR2017'd; dif=(11*30/30)/360;       output;
    _start='12APR2017'd; _end='20APR2017'd; dif=(9*30/30)/360;        output;
    _start='21APR2017'd; _end='30APR2017'd; dif=(10*30/30)/360;       output;
    _start='01MAY2017'd; _end='31MAY2017'd; dif=(31*30/31)/360;       output;
    _start='01JUN2017'd; _end='30JUN2017'd; dif=(30*30/30)/360;       output;
    _start='01JUL2017'd; _end='31JUL2017'd; dif=(31*30/31)/360;       output;
    _start='01AUG2017'd; _end='31AUG2017'd; dif=(31*30/31)/360;       output;
    _start='01SEP2017'd; _end='30SEP2017'd; dif=(30*30/30)/360;       output;
    _start='01OCT2017'd; _end='31OCT2017'd; dif=(31*30/31)/360;       output;
    _start='01NOV2017'd; _end='30NOV2017'd; dif=(30*30/30)/360;       output;
    _start='01DEC2017'd; _end='31DEC2017'd; dif=(31*30/31)/360;       output;
run;

data one;
    set one;
    yrdif_func=yrdif(_start,_end+1,'30/360');  
run;

Both dif and yrdif _func give the same result up to 6 digits after the comma in the example above.

 

 

However I cannot explain it. Indeed, I would expect something more like this for January and February:

 

data two;    
    _start='01JAN2017'd; _end='15JAN2017'd; dif=(15*30/31)/360; output;
    _start='16JAN2017'd; _end='31JAN2017'd; dif=(16*30/31)/360; output;
    _start='01FEB2017'd; _end='14FEB2017'd; dif=(14*30/28)/360; output;
    _start='15FEB2017'd; _end='28FEB2017'd; dif=(14*30/28)/360; output;
...
run;

 

Are you aware of any reason for the way YRDIF is not matching my expectation?

 

Kind Regards,

 

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

And did you read the SAS help documents on this?

http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p1pmmr2dtec32an1vbsqmm3abil5.htm&...

 

Which says:

basis

identifies a character constant or variable that describes how SAS calculates a date difference or a person’s age. The following character strings are valid:

'30/360'

specifies a 30-day month and a 360-day year in calculating the number of years. Each month is considered to have 30 days, and each year 360 days, regardless of the actual number of days in each month or year.

Alias '360'
Tip If either date falls at the end of a month, it is treated as if it were the last day of a 30-day month.
xxformat_com
Barite | Level 11

Yes, I read it but it didn't help me clarifying how the computation work.

 

I can only image this for computation and find it strange as for same interval of time, you don't get the same weight in the year.

 

    _start='01JAN2017'd; _end='15JAN2017'd; dif=15/360; output;
    _start='16JAN2017'd; _end='31JAN2017'd; dif=30/360-15/360; output;
    _start='01FEB2017'd; _end='14FEB2017'd; dif=14/360; output;
    _start='15FEB2017'd; _end='28FEB2017'd; dif=30/360-14/360; output;
ChrisNZ
Tourmaline | Level 20
data TEST;    
  D1='01JAN2017'd; D2='16JAN2017'd; X=(D2-D1)/360; Y=yrdif(D1,D2,'30/360'); output;
  D1='16JAN2017'd; D2='31JAN2017'd; X=(D2-D1)/360; Y=yrdif(D1,D2,'30/360'); output;
  D1='01FEB2017'd; D2='15FEB2017'd; X=(D2-D1)/360; Y=yrdif(D1,D2,'30/360'); output;
  D1='12FEB2017'd; D2='28FEB2017'd; X=(D2-D1)/360; Y=yrdif(D1,D2,'30/360'); output;
run;

X and Y give the same result. Does that make more sense now?

Patrick
Opal | Level 21

@xxformat_com

Do you understand the concept of "ultimo" used by banks for example for interest calculations? (...not sure if that applies for all countries).

 

Basically: Each month has max. 30 days, the year has 360 days, the last of the month is always day 30. Any day below 30 is counted as the exact day unless it's the last day of the month (so the last day of February is day 30; depending on leap year or not that's then 25, 26, 30  or 25, 26, 27, 30). So if you want the number of days since  - let's say 1/1/2017 then that's the 30*full months plus number of days of current month (set to 30 as well if last day of the current month).

 

So that's the logic yrdif() with basis 360/30 uses.

 

'30/360'

specifies a 30-day month and a 360-day year in calculating the number of years. Each month is considered to have 30 days, and each year 360 days, regardless of the actual number of days in each month or year.

ballardw
Super User

@xxformat_com wrote:

 

data one;    
    _start='01JAN2017'd; _end='15JAN2017'd; dif=(15.5*30/31)/360;     output;
    _start='16JAN2017'd; _end='31JAN2017'd; dif=(15.5*30/31)/360;     output;
    _start='01FEB2017'd; _end='14FEB2017'd; dif=(13.06666*30/28)/360; output;
    _start='15FEB2017'd; _end='28FEB2017'd; dif=(14.93333*30/28)/360; output;
    _start='01MAR2017'd; _end='31MAR2017'd; dif=(31*30/31)/360;       output;
    _start='01APR2017'd; _end='11APR2017'd; dif=(11*30/30)/360;       output;
    _start='12APR2017'd; _end='20APR2017'd; dif=(9*30/30)/360;        output;
    _start='21APR2017'd; _end='30APR2017'd; dif=(10*30/30)/360;       output;
    _start='01MAY2017'd; _end='31MAY2017'd; dif=(31*30/31)/360;       output;
    _start='01JUN2017'd; _end='30JUN2017'd; dif=(30*30/30)/360;       output;
    _start='01JUL2017'd; _end='31JUL2017'd; dif=(31*30/31)/360;       output;
    _start='01AUG2017'd; _end='31AUG2017'd; dif=(31*30/31)/360;       output;
    _start='01SEP2017'd; _end='30SEP2017'd; dif=(30*30/30)/360;       output;
    _start='01OCT2017'd; _end='31OCT2017'd; dif=(31*30/31)/360;       output;
    _start='01NOV2017'd; _end='30NOV2017'd; dif=(30*30/30)/360;       output;
    _start='01DEC2017'd; _end='31DEC2017'd; dif=(31*30/31)/360;       output;
run;

data one;
    set one;
    yrdif_func=yrdif(_start,_end+1,'30/360');  
run;

Both dif and yrdif _func give the same result up to 6 digits after the comma in the example above.

 

 

However I cannot explain it. Indeed, I would expect something more like this for January and February:

 

data two;    
    _start='01JAN2017'd; _end='15JAN2017'd; dif=(15*30/31)/360; output;
    _start='16JAN2017'd; _end='31JAN2017'd; dif=(16*30/31)/360; output;
    _start='01FEB2017'd; _end='14FEB2017'd; dif=(14*30/28)/360; output;
    _start='15FEB2017'd; _end='28FEB2017'd; dif=(14*30/28)/360; output;
...
run;

 

Are you aware of any reason for the way YRDIF is not matching my expectation?

 

Kind Regards,

 


So, what is your expectation? We can't read your mind.

And what exactly are you attempting to do?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 902 views
  • 0 likes
  • 5 in conversation