<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: YRDIF() Function Returning Different Values for Same Date Spans in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845210#M334121</link>
    <description>Thank you for your help, I really do appreciate your feedback, sincerely&lt;BR /&gt;&lt;BR /&gt;After running through your feedback (and Reezas), I discovered the error was on my end and NOT the YRDIF() function itself.&lt;BR /&gt;&lt;BR /&gt;Thank you again for your help.</description>
    <pubDate>Fri, 18 Nov 2022 21:12:59 GMT</pubDate>
    <dc:creator>GBL__</dc:creator>
    <dc:date>2022-11-18T21:12:59Z</dc:date>
    <item>
      <title>YRDIF() Function Returning Different Values for Same Date Spans</title>
      <link>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845159#M334101</link>
      <description>&lt;P&gt;I am struggling to understand why a function with the same start and end dates is returning different values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;YEARS_ON_JOB_c and YEARS2 have the same definition, the first being formatted as 10.2 and latter having no format&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;YRDIF(start_date, DATE_OF_DATA, 'act/act')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current version: 9.04.01M7P080520&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="YRDIF what.JPG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77456i5840A02337758211/image-size/large?v=v2&amp;amp;px=999" role="button" title="YRDIF what.JPG" alt="YRDIF what.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 17:29:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845159#M334101</guid>
      <dc:creator>GBL__</dc:creator>
      <dc:date>2022-11-18T17:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: YRDIF() Function Returning Different Values for Same Date Spans</title>
      <link>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845166#M334105</link>
      <description>&lt;P&gt;We can't test SAS code against pictures, so posting pictures of data is useless and only a waste of time.&lt;/P&gt;
&lt;P&gt;Post data as SAS code, in data steps with datalines which recreate your data.&lt;/P&gt;
&lt;P&gt;And, whenever code does not work as expected, post the complete log of the step.&lt;/P&gt;
&lt;P&gt;Use the "little running man" for SAS code, and the &amp;lt;/&amp;gt; button for logs and text data.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 17:58:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845166#M334105</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-11-18T17:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: YRDIF() Function Returning Different Values for Same Date Spans</title>
      <link>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845170#M334107</link>
      <description>&lt;P&gt;Thanks, Kurt, for your most helpful response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me rephrase my question,&amp;nbsp; Why would the YRDIF function ever return two different values for the same date span?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for wasting both of ours time as well with your amazingly informative response&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 18:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845170#M334107</guid>
      <dc:creator>GBL__</dc:creator>
      <dc:date>2022-11-18T18:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: YRDIF() Function Returning Different Values for Same Date Spans</title>
      <link>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845200#M334116</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268542"&gt;@GBL__&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was able to reproduce your output (including all decimals shown) with my SAS&amp;nbsp;9.4M5 using the code below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value dfmt
22585-22949='10/31/2022';
run;

data test;
_=_n_+14058;
input (start_date DATE_OF_DATA)(:yymmdd.);
YEARS_ON_JOB_c = yrdif(start_date, DATE_OF_DATA, 'act/act');
YEARS2         = yrdif(start_date, DATE_OF_DATA, 'act/act');
format start_date mmddyy10. DATE_OF_DATA dfmt. YEARS_ON_JOB_c 10.2;
cards;
2020-11-01 2022-07-07
2020-11-01 2022-07-13
2020-11-01 2022-07-19
2020-10-31 2022-05-31
2020-10-31 2022-05-17
2020-10-31 2022-10-10
2020-10-31 2022-10-31
2020-10-31 2022-09-14
2020-10-31 2022-08-24
2020-10-30 2022-10-17
2020-10-30 2022-10-21
2020-10-30 2022-09-29
2020-10-30 2022-10-03
2020-10-30 2022-05-04
;

proc print data=test noobs;
format years2 best12.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think it is more likely that the YRDIF results were obtained with the dates shown in the data lines above than with other suitable dates, which in turn is &lt;EM&gt;much&lt;/EM&gt; more likely than that they were obtained with a constant&amp;nbsp;&lt;FONT face="courier new,courier"&gt;DATE_OF_DATA='31OCT2022'd&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;start_date='01NOV2020'd&lt;/FONT&gt;, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a first step I would print those observations using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format DATE_OF_DATA yymmdd10.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in the PROC PRINT step to avoid the often confusing effect of unexpected formats (such as &lt;FONT face="courier new,courier"&gt;dfmt.&lt;/FONT&gt; above).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this constantly showed DATE_OF_DATA as&amp;nbsp;&lt;FONT face="courier new,courier"&gt;2022-10-31&lt;/FONT&gt;, I would scrutinize the log containing the YRDIF function calls to check if the arguments were really &lt;FONT face="courier new,courier"&gt;start_date&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;DATE_OF_DATA&lt;/FONT&gt;&amp;nbsp;and if there is any chance that either of these variables had different values (than it has now) when the year differences were computed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The final examination, if needed, would be to run more and more simplified versions of the code on the input dataset(s), restricted to a few suitable observations. If the incorrect results persist, please show us that simplified code and those few observations (in the form of a data step).&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 20:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845200#M334116</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-11-18T20:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: YRDIF() Function Returning Different Values for Same Date Spans</title>
      <link>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845206#M334119</link>
      <description>I would triple check my assumptions that they're the same formula.</description>
      <pubDate>Fri, 18 Nov 2022 21:01:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845206#M334119</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-18T21:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: YRDIF() Function Returning Different Values for Same Date Spans</title>
      <link>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845209#M334120</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268542"&gt;@GBL__&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks, Kurt, for your most helpful response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me rephrase my question,&amp;nbsp; Why would the YRDIF function ever return two different values for the same date span?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for wasting both of ours time as well with your amazingly informative response&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You still didn't post the actual values.&amp;nbsp; As the last two column in your picture show you really cannot depend on how the values LOOK to know what the value actually is.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 21:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845209#M334120</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-18T21:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: YRDIF() Function Returning Different Values for Same Date Spans</title>
      <link>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845210#M334121</link>
      <description>Thank you for your help, I really do appreciate your feedback, sincerely&lt;BR /&gt;&lt;BR /&gt;After running through your feedback (and Reezas), I discovered the error was on my end and NOT the YRDIF() function itself.&lt;BR /&gt;&lt;BR /&gt;Thank you again for your help.</description>
      <pubDate>Fri, 18 Nov 2022 21:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/YRDIF-Function-Returning-Different-Values-for-Same-Date-Spans/m-p/845210#M334121</guid>
      <dc:creator>GBL__</dc:creator>
      <dc:date>2022-11-18T21:12:59Z</dc:date>
    </item>
  </channel>
</rss>

