<?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: Creating an integer age in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-integer-age/m-p/235827#M43157</link>
    <description>&lt;P&gt;The third parameter of yrdif should be "age". If you don't get error messages it may be that that part of the code is never executed. All attempts I have made to generate missing values resulted in error messages. This is what I tried:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
/* Proper dates */
patdobD = '15JAN2000'd; 
patadmD = '15JAN2015'd; 
/* Non integer dates */
patdobDF = '15JAN2000'd + 0.4; 
patadmDF = '15JAN2015'd + 0.6; 
/* Datetimes instead of dates */
patdobDT = '15JAN2000:00:00:00'dt; 
patadmDT = '15JAN2015:00:00:00'dt; 
format patdobD patadmD patdobDF patadmDF date9. 
    patdobDT patadmDT datetime.;
do type = "actual", "age";
    /* Age calculation with proper dates */
    ageD = yrdif(patdobD, patadmD, type);
    /* Age calculation with fractional dates */
    ageDF = yrdif(patdobDF, patadmDF, type);
    /* Age calculation with datetimes */
    ageDT = yrdif(patdobDT, patadmDT, type);
    /* Age calculation with missing value */
    ageMiss = yrdif(patdobD, ., type);
    /* Age calculation with dates in reversed order*/
    ageReverse = yrdif(patadmD, patdobD, type);
    put (_all_) (=/) /;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 21 Nov 2015 04:19:18 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2015-11-21T04:19:18Z</dc:date>
    <item>
      <title>Creating an integer age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-integer-age/m-p/235796#M43148</link>
      <description>&lt;P&gt;Hi!&amp;nbsp; I have the following syntax, but the&amp;nbsp;PATAGE variable I created is just spitting out "." in all value slots.&amp;nbsp; Can&amp;nbsp;someone please tell me where my error is?&amp;nbsp; Thanks!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; want;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;keep&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; admdate admdx DX1-DX20 marital pasth bencatx patdob dds dispdate dmisbenf dmissex ethnic pasth patcat patname paygrade &lt;/FONT&gt;&lt;/FONT&gt;prvadm race patage recage;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;format&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; dispdate &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;mmddyy10.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;format&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; admdate &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;mmddyy10.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;format&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; birtdate &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;mmddyy10.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;patdob =birtdate;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;format&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; patdob &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;mmddyy10.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;patage= Int(yrdif(N_patdob,N_admdate,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'actual'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;run&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2015 22:34:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-integer-age/m-p/235796#M43148</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2015-11-20T22:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an integer age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-integer-age/m-p/235799#M43149</link>
      <description>&lt;P&gt;For us to really know what's going on you need to provide sample data for "have".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the SAS log telling you? Any warnings or notes about unititialized variables or missing values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just by looking into your code:&lt;/P&gt;
&lt;P&gt;- N_patdob and N_admdate are variables sourced&amp;nbsp;from "have". What are their values? If any of the two is missing then the result will be missing.&lt;/P&gt;
&lt;P&gt;- &amp;nbsp;Instead of &lt;STRONG&gt;&lt;EM&gt;&lt;FONT face="Courier New" size="2"&gt;Int(yrdif(N_patdob,N_admdate,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'actual'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;))&lt;/FONT&gt;&lt;/FONT&gt;&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;use &lt;STRONG&gt;&lt;EM&gt;intck('year',N_patdob,N_admdate,'c')&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2015 23:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-integer-age/m-p/235799#M43149</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-11-20T23:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an integer age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-integer-age/m-p/235800#M43150</link>
      <description>&lt;P&gt;Without seeing sample data it's hard to say exactly what's wrong. Try adding n_patdob , n_admdate to your keep statement to make sure they have values and are valid numerics (SAS dates presumably).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you could post some sample of your data, masked if it's a matter of P.H.I or P.I.I. Your approach seems fine though syntactically as this works..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data _null_;
   n_patdob='10APR1988'd;
   n_admdate='20NOV2015'd;
   int_age_act=int(yrdif(n_patdob, n_admdate, 'actual'));
   put int_age_act= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Nov 2015 23:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-integer-age/m-p/235800#M43150</guid>
      <dc:creator>JoshB</dc:creator>
      <dc:date>2015-11-20T23:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an integer age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-integer-age/m-p/235827#M43157</link>
      <description>&lt;P&gt;The third parameter of yrdif should be "age". If you don't get error messages it may be that that part of the code is never executed. All attempts I have made to generate missing values resulted in error messages. This is what I tried:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
/* Proper dates */
patdobD = '15JAN2000'd; 
patadmD = '15JAN2015'd; 
/* Non integer dates */
patdobDF = '15JAN2000'd + 0.4; 
patadmDF = '15JAN2015'd + 0.6; 
/* Datetimes instead of dates */
patdobDT = '15JAN2000:00:00:00'dt; 
patadmDT = '15JAN2015:00:00:00'dt; 
format patdobD patadmD patdobDF patadmDF date9. 
    patdobDT patadmDT datetime.;
do type = "actual", "age";
    /* Age calculation with proper dates */
    ageD = yrdif(patdobD, patadmD, type);
    /* Age calculation with fractional dates */
    ageDF = yrdif(patdobDF, patadmDF, type);
    /* Age calculation with datetimes */
    ageDT = yrdif(patdobDT, patadmDT, type);
    /* Age calculation with missing value */
    ageMiss = yrdif(patdobD, ., type);
    /* Age calculation with dates in reversed order*/
    ageReverse = yrdif(patadmD, patdobD, type);
    put (_all_) (=/) /;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Nov 2015 04:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-integer-age/m-p/235827#M43157</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-11-21T04:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an integer age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-integer-age/m-p/235869#M43163</link>
      <description>&lt;P&gt;Just one more piece of advice: It's always helpful for yourself and for people who read or work with your programs to keep the code consistent, even in cases where this consistency is not necessary for proper functioning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;SPAN style="line-height: 20px;"&gt;Y&lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;ou bother to format variable BIRTDATE nicely, although this variable is not kept (hence dropped) anyway, so that the assigned format&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;will never be effective.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN style="line-height: 20px;"&gt;It looks like variable PATDOB takes over from BIRTDATE. If it's just a change of names, you can use a RENAME statement (or RENAME= dataset option) to achieve this more easily.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN style="line-height: 20px;"&gt;It's a bit odd that neither the just created numeric date variable PATDOB (patient's date of birth, I guess) is used in the calculation of PATAGE (presumably patient's age), nor the numeric date variable ADMDATE. Instead, you use two seemingly similar variables N_PATDOB and N_ADMDATE. Does the "N_" prefix, by any chance, stand for "numeric", i.e. SAS date value as opposed to a date in a human-readable format?&amp;nbsp;If so, what is the difference to PATDOB and ADMDATE, then?&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Sat, 21 Nov 2015 23:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-integer-age/m-p/235869#M43163</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-21T23:15:44Z</dc:date>
    </item>
  </channel>
</rss>

