<?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: date difference in year between two date YYMMDDN8. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889903#M82902</link>
    <description>&lt;P&gt;Since it first happens in observation 31, it lets me suspect the previous dates were convertible. What does PROC CONTENTS say about the date variables you start with?&lt;/P&gt;</description>
    <pubDate>Fri, 18 Aug 2023 14:41:20 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-08-18T14:41:20Z</dc:date>
    <item>
      <title>date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889875#M82892</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I want to obtain date difference in year between two dates in&amp;nbsp;YYMMDDN8. format&lt;/P&gt;
&lt;P&gt;I write this code but it result in an empty Colum for age&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Age = yrdif(FIRST_OFFER_DT, caldt, 'AGEYear');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 13:43:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889875#M82892</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2023-08-18T13:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889885#M82893</link>
      <description>&lt;P&gt;If you run PROC CONTENTS on the dataset, are FIRST_OFFER_DT and CALDT numeric or character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If they are character, you will need to use the INPUT function to convert them into SAS dates before doing any calculations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For difference in &lt;EM&gt;years&lt;/EM&gt; between two dates, you'll also think about how you want to define a year.&amp;nbsp; See the BASIS option to YRDIF, or look at INTCK().&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889885#M82893</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-18T14:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889888#M82894</link>
      <description>&lt;P&gt;Can you post the log from running your code?&amp;nbsp; 'AGEyear' is not a valid value for the third parameter, perhaps you want 'AGE'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As is, you should see bad messages in the log:&lt;/P&gt;
&lt;PRE&gt;NOTE: Invalid argument to function YRDIF...

NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values.
&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889888#M82894</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-18T14:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889891#M82895</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Invalid argument to function YRDIF(9104,9190,'AGEYear') at ligne 78 colonne 7.
Rank_NO=1 CRSP_FUNDNO=000053 MRET=1.000624 CALDT=19850228 FIRST_OFFER_DT=19841204 Age=. _ERROR_=1 _N_=
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889891#M82895</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2023-08-18T14:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889894#M82896</link>
      <description>&lt;P&gt;If your "date" is actually the &lt;EM&gt;number&lt;/EM&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;19850228&lt;/LI-CODE&gt;
&lt;P&gt;(something close to 2 million), then this is way beyond the range of dates the SAS functions are meant to deal with. You need to first convert such values to real SAS dates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;caldt = input(put(caldt,z8.),yymmdd8.);
format caldt yymmdd10.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:24:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889894#M82896</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-18T14:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889895#M82897</link>
      <description>&lt;P&gt;It does not matter what format you have attached to the variable to control how it prints.&amp;nbsp; But it does need to have actual DATE values.&lt;/P&gt;
&lt;P&gt;You need to use the AGE option, which will calculate age in years, since there is no AGEYEAR option.&lt;/P&gt;
&lt;PRE&gt;845  data test;
846    first_offer_dt = '01JAN2019'd;
847    caldt = today();
848    Age = yrdif(FIRST_OFFER_DT, caldt, 'AGE');
849    put (_all_) (=/);
850    put (first_offer_dt caldt) (=date9.);
851    put (first_offer_dt caldt) (=yymmdd10.);
852  run;


first_offer_dt=21550
caldt=23240
Age=4.6273972603
first_offer_dt=01JAN2019 caldt=18AUG2023
first_offer_dt=2019-01-01 caldt=2023-08-18
&lt;/PRE&gt;
&lt;P&gt;If you want to eliminate the fractional part of the result you can use INT() to get normal age result. Or perhaps use ROUND() if you want something different.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:24:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889895#M82897</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-18T14:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889896#M82898</link>
      <description>&lt;P&gt;It looks like you have valid SAS date values, so that's good news.&amp;nbsp; I think the only problem is that you used 'AGEyear' as the third argument rather than 'Age'.&amp;nbsp; When I run with your values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;
  FIRST_OFFER_DT="04Dec1984"d ;
  CALDT="28Feb1985"d ;

  Age = yrdif(FIRST_OFFER_DT, CALDT, 'AGE');

  put (FIRST_OFFER_DT CALDT AGE)(=) ;
  format CALDT FIRST_OFFER_DT yymmddn8. ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I get:&lt;/P&gt;
&lt;PRE&gt;1    data _null_ ;
2      FIRST_OFFER_DT="04Dec1984"d ;
3      CALDT="28Feb1985"d ;
4
5      Age = yrdif(FIRST_OFFER_DT, CALDT, 'AGE');
6
7      put (FIRST_OFFER_DT CALDT AGE)(=) ;
8      format CALDT FIRST_OFFER_DT yymmddn8. ;
9    run ;

FIRST_OFFER_DT=19841204 CALDT=19850228 Age=0.2356164384
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889896#M82898</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-18T14:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889899#M82899</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

53   data JOINT_FO1;
54   set JOINT_FO;
55   caldt = input(put(caldt,z8.),yymmdd8.);
56   format caldt yymmdd10.;
57   run;

NOTE: Invalid argument to function INPUT at ligne 55 colonne 9.
Rank_NO=1 CRSP_FUNDNO=000053 MRET=1.024799 CALDT=. FIRST_OFFER_DT=19841204 _ERROR_=1 _N_=31
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889899#M82899</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2023-08-18T14:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889901#M82900</link>
      <description>the problem is that this program generate a lot of message in the log&lt;BR /&gt;&lt;BR /&gt;FIRST_OFFER_DT=19830101 CALDT=. Age=.&lt;BR /&gt;FIRST_OFFER_DT=19830101 CALDT=. Age=.&lt;BR /&gt;FIRST_OFFER_DT=19830101 CALDT=. Age=.&lt;BR /&gt;FIRST_OFFER_DT=19830101 CALDT=. Age=.&lt;BR /&gt;FIRST_OFFER_DT=19830101 CALDT=. Age=.&lt;BR /&gt;FIRST_OFFER_DT=19830101 CALDT=. Age=.&lt;BR /&gt;FIRST_OFFER_DT=19830101 CALDT=. Age=.&lt;BR /&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889901#M82900</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2023-08-18T14:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889902#M82901</link>
      <description>&lt;P&gt;You cannot calculate an age from missing values.&lt;/P&gt;
&lt;P&gt;Why not just only attempt it when you have both date values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:40:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889902#M82901</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-18T14:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889903#M82902</link>
      <description>&lt;P&gt;Since it first happens in observation 31, it lets me suspect the previous dates were convertible. What does PROC CONTENTS say about the date variables you start with?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889903#M82902</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-18T14:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889904#M82903</link>
      <description>&lt;P&gt;this is th output of proc contents&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Contents: Variables" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="l data"&gt;CALDT&lt;/TD&gt;
&lt;TD class="l data"&gt;Num.&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="l data"&gt;YYMMDD10.&lt;/TD&gt;
&lt;TD class="l data"&gt;YYMMDD8.&lt;/TD&gt;
&lt;TD class="l data"&gt;Date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;CRSP_FUNDNO&lt;/TD&gt;
&lt;TD class="l data"&gt;Num.&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="l data"&gt;Z6.&lt;/TD&gt;
&lt;TD class="l data"&gt;6.&lt;/TD&gt;
&lt;TD class="l data"&gt;Fund Identifier&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="l data"&gt;FIRST_OFFER_DT&lt;/TD&gt;
&lt;TD class="l data"&gt;Num.&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="l data"&gt;YYMMDDN8.&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;Date the Fund Was First Offered (from header data)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="l data"&gt;MRET&lt;/TD&gt;
&lt;TD class="l data"&gt;Num.&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="l data"&gt;9.6&lt;/TD&gt;
&lt;TD class="l data"&gt;9.6&lt;/TD&gt;
&lt;TD class="l data"&gt;Total Return per Share as of Month End&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;Rank_NO&lt;/TD&gt;
&lt;TD class="l data"&gt;Num.&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:44:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889904#M82903</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2023-08-18T14:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889909#M82904</link>
      <description>&lt;P&gt;You have records in your data where CALDT is missing.&amp;nbsp; If you expect this to happen, and want to have AGE be missing when this happens, you can make the calculation of AGE conditional on both FIRST_OFFER_DT and CALDT being non-missing, like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if n(FIRST_OFFER_DT, CALDT)=2 then Age = yrdif(FIRST_OFFER_DT, CALDT, 'AGE');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could impute a value for CALDT when it is missing.&lt;/P&gt;
&lt;P&gt;But if you're surprised that CALDT is sometimes missing, then you should go back in your program&amp;nbsp; / data earlier to figure out why CALDT is sometimes missing.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889909#M82904</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-18T14:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: date difference in year between two date YYMMDDN8.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889910#M82905</link>
      <description>&lt;P&gt;This means no conversion is needed; you should apply the YYMMDD10. format to all your date variables to avoid confusion.&lt;/P&gt;
&lt;P&gt;Both the YRDIF and INTCK functions should work, as long as the parameters are valid. Missing input values will result in missing output values.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/date-difference-in-year-between-two-date-YYMMDDN8/m-p/889910#M82905</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-18T14:58:59Z</dc:date>
    </item>
  </channel>
</rss>

