<?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: problems with calculating age in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/problems-with-calculating-age/m-p/350214#M81385</link>
    <description>&lt;P&gt;everywhere you need that text variable you should be able to use&lt;/P&gt;
&lt;P&gt;input(t1.variablename,yymmdd8.) to convert the text into a SAS data value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Day(input(t1.datebegin_At_Clo ,yymmdd8.)&amp;nbsp;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I must say, just because the feds do doesn't mean you have to persist. You could have read your local version of the data into a SAS date value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since I have caught CDC doing some very poor calculations with character values improperly converted to numerics using string functions I watch such things. (We had a person with a height of 11inches because CDC parsed, without catching, a value of 5011 which would have meant 50 feet 11 inches using SUBSTR)&lt;/P&gt;</description>
    <pubDate>Fri, 14 Apr 2017 23:07:18 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-04-14T23:07:18Z</dc:date>
    <item>
      <title>problems with calculating age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problems-with-calculating-age/m-p/350206#M81382</link>
      <description>&lt;P&gt;I am using the most recent version of Enterprise Guide (7.1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a function I have used for years successfully to calculate age. It's&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;((floor ((intck('month',

T1.DATEOFBIRTH,

T1.DATEBEGIN_AT_CLO) - (day (T1.DATEBEGIN_AT_CLO) &amp;lt; day (T1.DATEOFBIRTH)))/12) )
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Where I want to calculate age at datebegin_At_Clo .The problem here is that I am starting with a date stored as a text field (I did not generate it the federal government does and I do not know how they formatted it except that it is a string).&lt;BR /&gt;&lt;BR /&gt; It is of the form '19761026' where the first four digits are the year, the next two the month and the next two the days. &lt;BR /&gt;&lt;BR /&gt; I ran &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WORK.QUERY_FOR_Q16 AS 
SELECT t1.DateOfBirth, 
t1.ClosureDate, 
/* DOB */
(INPUT(t1.DateOfBirth, yyyymmdd10.)) LABEL="DOB" AS DOB, 
/* CD */
(INPUT(t1.ClosureDate, yyyymmdd10.)) LABEL="CD" AS CD
FROM WORK.Q16 t1;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt; and it appears to generate a number fine. However when I use the new fields (DOB and CD) in the age function above I get no results (not errors just all missing data).&lt;BR /&gt;&lt;BR /&gt; That is I get&amp;nbsp;missing data&amp;nbsp;when I run&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WORK.QUERY_FOR_Q16_0000 AS 
SELECT t1.DateOfBirth, 
t1.ClosureDate, 
/* Age */
(((floor ((intck('month',

T1.Dob,

T1.cd) - (day (T1.cd) &amp;lt; day (T1.Dob)))/12) )
)
) LABEL="Age" AS Age
FROM WORK.QUERY_FOR_Q16 t1;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;** Edited to use CODE boxes.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2017 23:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problems-with-calculating-age/m-p/350206#M81382</guid>
      <dc:creator>noetsi</dc:creator>
      <dc:date>2017-04-14T23:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: problems with calculating age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problems-with-calculating-age/m-p/350214#M81385</link>
      <description>&lt;P&gt;everywhere you need that text variable you should be able to use&lt;/P&gt;
&lt;P&gt;input(t1.variablename,yymmdd8.) to convert the text into a SAS data value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Day(input(t1.datebegin_At_Clo ,yymmdd8.)&amp;nbsp;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I must say, just because the feds do doesn't mean you have to persist. You could have read your local version of the data into a SAS date value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since I have caught CDC doing some very poor calculations with character values improperly converted to numerics using string functions I watch such things. (We had a person with a height of 11inches because CDC parsed, without catching, a value of 5011 which would have meant 50 feet 11 inches using SUBSTR)&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2017 23:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problems-with-calculating-age/m-p/350214#M81385</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-14T23:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: problems with calculating age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problems-with-calculating-age/m-p/350217#M81386</link>
      <description>&lt;P&gt;I suspect that you actually read the string like '20170414' as a NUMBER and then assigned it to a character variable and so SAS used the default format of BEST12. and so stored ' &amp;nbsp; &amp;nbsp;20140414' into the variable that you are trying to convert to a date. The leading spaces are causing trouble, but can be hard to see since normally SAS removes them when you PUT the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add a LEFT() or STRIP() function call and see if it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;,input(left(datechar),yymmdd8.) as dob format=yymmdd10. label='Date of Birth'&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Apr 2017 23:44:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problems-with-calculating-age/m-p/350217#M81386</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-04-14T23:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: problems with calculating age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problems-with-calculating-age/m-p/350218#M81387</link>
      <description>&lt;P&gt;The following works for me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data q16;
  informat DateOfBirth ClosureDate $10.;
  input DateOfBirth ClosureDate;
  cards;
19761026 20170414
19440415 20170414
;
PROC SQL;
  CREATE TABLE QUERY_FOR_Q16 AS 
    SELECT INPUT(DateOfBirth, yymmdd8.) LABEL="DOB" AS DOB, 
      /* CD */
      INPUT(ClosureDate, yymmdd8.) LABEL="CD" AS CD,
      yrdif(calculated DOB,calculated CD,'AGE') as age
         FROM Q16
  ;
QUIT;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2017 23:47:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problems-with-calculating-age/m-p/350218#M81387</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-04-14T23:47:31Z</dc:date>
    </item>
  </channel>
</rss>

