<?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: In Search of a More Elegant Solution using String Functions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/In-Search-of-a-More-Elegant-Solution-using-String-Functions/m-p/326689#M72808</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date_of_birth = input(main_dob,yymmdd10.);
format date_of_birth ddmmyys10.;

contract_age = intck('year',date_of_birth,contract_start_date_dt);
/* or */
contract_age = year(contract_start_date_dt) - year(date_of_birth);
/* or */
contract_age = (contract_start_date_dt - date_of_birth) / 365.25;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have a date as SAS date (days from 01/01/1960), such calculations become easy.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Jan 2017 12:11:31 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-01-23T12:11:31Z</dc:date>
    <item>
      <title>In Search of a More Elegant Solution using String Functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/In-Search-of-a-More-Elegant-Solution-using-String-Functions/m-p/326684#M72807</link>
      <description>&lt;P&gt;Given the following SAS Code which is applied to a SAS Date Set containing several explanatory variables and specifically a CHAR Variable: MAIN_DOB which contains the date of birth of the main applicant in the following format: 1978-06-28&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We need to calculate the age of the applicant in years at the time of contract initiation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Contract_Start_Date_DT is a SAS Date in the format 25/06/2014&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following SAS Code works but surely there is a more elegant / efficient solution &amp;nbsp;to this simple problem&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA&lt;BR /&gt;LIBXYZ.DEVELOPMENT_SAMPLE_03 ;&lt;/P&gt;&lt;P&gt;SET LIBXYZ.DEVELOPMENT_SAMPLE_02 ;&lt;/P&gt;&lt;P&gt;SearchDate_DT = DATEPART(SearchDate) ;&lt;BR /&gt;QuoteDate_DT = DATEPART(QuoteDate) ;&lt;BR /&gt;Contract_StartDate_DT = DATEPART(Contract_StartDate) ;&lt;BR /&gt;Vehicle_RegistrationDate_DT = DATEPART(Vehicle_RegistrationDate) ;&lt;BR /&gt;Termination_Date_DT = DATEPART(Termination_Date) ;&lt;BR /&gt;Termination_CarDisposalDate_DT = DATEPART(Termination_CarDisposalDate) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DateOfBirth_Char = INPUT( COMPRESS( MAIN_DOB,"-" ) , $8. ) ;&lt;/P&gt;&lt;P&gt;DateOfBirth_Year = INPUT( SUBSTR(DateOfBirth_Char , 1 , 4 ) , 4. ) ;&lt;/P&gt;&lt;P&gt;DateOfBirth_Month = INPUT( SUBSTR(DateOfBirth_Char , 5 , 2 ) , 2. ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF DateOfBirth_Month &amp;lt; 10&lt;BR /&gt;THEN DateOfBirth_Month1 = CAT('0' , DateOfBirth_Month ) ;&lt;BR /&gt;ELSE DateOfBirth_Month1 = DateOfBirth_Month ;&lt;/P&gt;&lt;P&gt;DateOfBirth_Day = INPUT( SUBSTR(DateOfBirth_Char , 7 , 2 ) , 2. ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF DateOfBirth_Day &amp;lt; 10&lt;BR /&gt;THEN DateOfBirth_Day1 = CAT('0' , DateOfBirth_Day ) ;&lt;BR /&gt;ELSE DateOfBirth_Day1 = DateOfBirth_Day ;&lt;/P&gt;&lt;P&gt;DateOfBirth = INPUT(CATX( '/' , DateOfBirth_Day1 , DateOfBirth_Month1 , DateOfBirth_Year ) , ddmmyy10. ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FORMAT SearchDate_DT QuoteDate_DT Contract_StartDate_DT Vehicle_RegistrationDate_DT Termination_Date_DT Termination_CarDisposalDate_DT ddmmyy10. ;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;FORMAT DateOfBirth ddmmyy10. ;&lt;BR /&gt;&lt;BR /&gt;CONTRACT_AGE = ( YEAR(Contract_StartDate_DT) - DateOfBirth_Year ) ;&lt;/P&gt;&lt;P&gt;FORMAT CONTRACT_AGE 4. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DROP SearchDate QuoteDate Contract_StartDate Vehicle_RegistrationDate Termination_Date Termination_CarDisposalDate&lt;BR /&gt;DateOfBirth_Char DateOfBirth_Year DateOfBirth_Month DateOfBirth_Day DateOfBirth_Day1 DateOfBirth_Month1 ;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for kind assistance&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 12:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/In-Search-of-a-More-Elegant-Solution-using-String-Functions/m-p/326684#M72807</guid>
      <dc:creator>JonDickens1607</dc:creator>
      <dc:date>2017-01-23T12:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: In Search of a More Elegant Solution using String Functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/In-Search-of-a-More-Elegant-Solution-using-String-Functions/m-p/326689#M72808</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date_of_birth = input(main_dob,yymmdd10.);
format date_of_birth ddmmyys10.;

contract_age = intck('year',date_of_birth,contract_start_date_dt);
/* or */
contract_age = year(contract_start_date_dt) - year(date_of_birth);
/* or */
contract_age = (contract_start_date_dt - date_of_birth) / 365.25;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have a date as SAS date (days from 01/01/1960), such calculations become easy.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 12:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/In-Search-of-a-More-Elegant-Solution-using-String-Functions/m-p/326689#M72808</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-01-23T12:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: In Search of a More Elegant Solution using String Functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/In-Search-of-a-More-Elegant-Solution-using-String-Functions/m-p/326724#M72818</link>
      <description>Thank you&lt;BR /&gt;&lt;BR /&gt;I will implement this and let you know if it works in my application.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Mon, 23 Jan 2017 14:57:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/In-Search-of-a-More-Elegant-Solution-using-String-Functions/m-p/326724#M72818</guid>
      <dc:creator>JonDickens1607</dc:creator>
      <dc:date>2017-01-23T14:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: In Search of a More Elegant Solution using String Functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/In-Search-of-a-More-Elegant-Solution-using-String-Functions/m-p/326730#M72820</link>
      <description>&lt;P&gt;And another&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt; contract_age = yrdif(date_of_birth,contract_start_date_dt,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'ACT/ACT'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;Though you may want to truncate or round&amp;nbsp;the result.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 15:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/In-Search-of-a-More-Elegant-Solution-using-String-Functions/m-p/326730#M72820</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-23T15:07:28Z</dc:date>
    </item>
  </channel>
</rss>

