DATA Step, Macro, Functions and more

Yrdif function - computation behind 30/360

Reply
Occasional Contributor
Posts: 7

Yrdif function - computation behind 30/360

[ Edited ]

 

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,

 

Super User
Super User
Posts: 9,221

Re: Yrdif function - computation behind 30/360

Posted in reply to xxformat_com

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.
Occasional Contributor
Posts: 7

Re: Yrdif function - computation behind 30/360

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;
PROC Star
Posts: 2,231

Re: Yrdif function - computation behind 30/360

Posted in reply to xxformat_com
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?

Respected Advisor
Posts: 4,557

Re: Yrdif function - computation behind 30/360

Posted in reply to xxformat_com

@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.

Super User
Posts: 13,066

Re: Yrdif function - computation behind 30/360

Posted in reply to xxformat_com

@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?

Ask a Question
Discussion stats
  • 5 replies
  • 104 views
  • 0 likes
  • 5 in conversation