<?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: calculating age using the first date of visit in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508034#M1581</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Add an IF statement to your code to only calculate age when DOB is not missing.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For example, you could introduce&amp;nbsp;the IF condition &lt;FONT face="courier new,courier"&gt;n(dob, dov)=2&lt;/FONT&gt;, which means "&lt;FONT face="courier new,courier"&gt;dob&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;dov&lt;/FONT&gt; are not missing":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if first.subject then do;
  &lt;FONT color="#008000"&gt;if n(dob, dov)=2 then&lt;/FONT&gt; age= &lt;EM&gt;(your age formula here)&lt;/EM&gt;;
  &lt;FONT color="#008000"&gt;else age=.;&lt;/FONT&gt;
end;&lt;/PRE&gt;
&lt;P&gt;Are you sure you want &lt;FONT face="courier new,courier"&gt;'actual'&lt;/FONT&gt; as the third argument of &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p1pmmr2dtec32an1vbsqmm3abil5.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;YRDIF&lt;/A&gt; given that &lt;FONT face="courier new,courier"&gt;'age'&lt;/FONT&gt; is an option designed for calculating a person's age?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 27 Oct 2018 22:03:12 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2018-10-27T22:03:12Z</dc:date>
    <item>
      <title>calculating age using the first date of visit</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508022#M1574</link>
      <description>&lt;P&gt;&lt;BR /&gt;DATA all_age;&lt;BR /&gt;SET all;&lt;BR /&gt;BY subject dov;&lt;BR /&gt;RETAIN subject;&lt;BR /&gt;IF first.dov THEN age=(dov-dob)/365.25;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi, can someone help me figure out how to only calculate age using only the first date of visit from the first subject as there are multiple outputs per subject. And applying that age to the rest of the data for the same subject? Just a student pulling out some hair... help plz!&lt;/P&gt;</description>
      <pubDate>Sat, 27 Oct 2018 21:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508022#M1574</guid>
      <dc:creator>rg529</dc:creator>
      <dc:date>2018-10-27T21:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: calculating age using the first date of visit</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508024#M1575</link>
      <description>&lt;P&gt;Based on your description,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my understanding is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;DATA all_age;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SET all;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;BY subject dov;&lt;/SPAN&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;RETAIN age;&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;SPAN&gt;IF first.dov THEN age=(dov-dob)/365.25;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Oct 2018 21:03:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508024#M1575</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-27T21:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: calculating age using the first date of visit</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508026#M1576</link>
      <description>&lt;P&gt;Please post sample data ?&lt;/P&gt;&lt;P&gt;It is unclear what format your dov and dob are in are they SAS dates ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Oct 2018 21:07:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508026#M1576</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-10-27T21:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: calculating age using the first date of visit</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508027#M1577</link>
      <description>yes in sas dates sorry let me post&lt;BR /&gt;</description>
      <pubDate>Sat, 27 Oct 2018 21:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508027#M1577</guid>
      <dc:creator>rg529</dc:creator>
      <dc:date>2018-10-27T21:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: calculating age using the first date of visit</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508029#M1578</link>
      <description>&lt;DIV class="sasNote"&gt;all dates are in SAS format, and the below code works, THANK YOU.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;DATA all_age;&lt;BR /&gt;SET all;&lt;BR /&gt;BY subject;&lt;BR /&gt;RETAIN age;&lt;BR /&gt;IF first.subject THEN age=YRDIF(dob, dov, 'actual');&lt;BR /&gt;RUN;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;BUT getting this error message in log?&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;DIV class="sasNote"&gt;NOTE: Invalid argument to function YRDIF(.,14193,'actual') at line 77 column 27.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;subject=102 dov=14193 dbp=73 sbp=128 site=1 gender=F dob=. doe=14193 smoke=0 drink=4 marital=3 education=3 glucose=119 height=62&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;weight=160 hdl=54 ldl=151 tg=133 tc=238 chd=1 pregnancy=0 exercise=0 FIRST.subject=1 LAST.subject=0 age=. _ERROR_=1 _N_=285&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;also for some reason using the dov-dob/365 is not working with code above&lt;/P&gt;</description>
      <pubDate>Sat, 27 Oct 2018 21:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508029#M1578</guid>
      <dc:creator>rg529</dc:creator>
      <dc:date>2018-10-27T21:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: calculating age using the first date of visit</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508030#M1579</link>
      <description>&lt;P&gt;You can't have missing values as an argument to yrdif as log explains&amp;nbsp;&lt;SPAN&gt;YRDIF(.,14193,'actual')&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you want more help, please post&amp;nbsp; a good representative sample of what you have&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Oct 2018 21:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508030#M1579</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-27T21:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: calculating age using the first date of visit</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508032#M1580</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/242969"&gt;@rg529&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;DIV class="sasNote"&gt;all dates are in SAS format, and the below code works, THANK YOU.&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;DATA all_age;&lt;BR /&gt;SET all;&lt;BR /&gt;BY subject;&lt;BR /&gt;RETAIN age;&lt;BR /&gt;IF first.subject THEN age=YRDIF(dob, dov, 'actual');&lt;BR /&gt;RUN;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;BUT getting this error message in log?&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;
&lt;DIV class="sasNote"&gt;NOTE: Invalid argument to function YRDIF(.,14193,'actual') at line 77 column 27.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;subject=102 dov=14193 dbp=73 sbp=128 site=1 gender=F &lt;STRONG&gt;dob=.&lt;/STRONG&gt; doe=14193 smoke=0 drink=4 marital=3 education=3 glucose=119 height=62&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;weight=160 hdl=54 ldl=151 tg=133 tc=238 chd=1 pregnancy=0 exercise=0 FIRST.subject=1 LAST.subject=0 age=. _ERROR_=1 _N_=285&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;also for some reason using the dov-dob/365 is not working with code above&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In that particular record, your dob is missing, so it cannot calculate an age.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if not missing(dob) then age = ...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add an IF statement to your code to only calculate age when DOB is not missing.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Oct 2018 21:34:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508032#M1580</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-27T21:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: calculating age using the first date of visit</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508034#M1581</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Add an IF statement to your code to only calculate age when DOB is not missing.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For example, you could introduce&amp;nbsp;the IF condition &lt;FONT face="courier new,courier"&gt;n(dob, dov)=2&lt;/FONT&gt;, which means "&lt;FONT face="courier new,courier"&gt;dob&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;dov&lt;/FONT&gt; are not missing":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if first.subject then do;
  &lt;FONT color="#008000"&gt;if n(dob, dov)=2 then&lt;/FONT&gt; age= &lt;EM&gt;(your age formula here)&lt;/EM&gt;;
  &lt;FONT color="#008000"&gt;else age=.;&lt;/FONT&gt;
end;&lt;/PRE&gt;
&lt;P&gt;Are you sure you want &lt;FONT face="courier new,courier"&gt;'actual'&lt;/FONT&gt; as the third argument of &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p1pmmr2dtec32an1vbsqmm3abil5.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;YRDIF&lt;/A&gt; given that &lt;FONT face="courier new,courier"&gt;'age'&lt;/FONT&gt; is an option designed for calculating a person's age?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Oct 2018 22:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculating-age-using-the-first-date-of-visit/m-p/508034#M1581</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-10-27T22:03:12Z</dc:date>
    </item>
  </channel>
</rss>

