<?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: Converting date to number forth and back in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-date-to-number-forth-and-back/m-p/715774#M221120</link>
    <description>&lt;P&gt;Typically this happens when the column in excel has mixed numeric (SAS and Excel store dates as numbers) and character values. So SAS defines the variable as character and the date values get stored as digit strings that represent the number that Excel uses for the date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you probably need to fist convert BDATE into a number and then add (the negative number) '30DEC1899'D to convert the number to a SAS date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SASDATE=input(BDATE,32.)+'30DEC1899'd ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example using the strings from your posted listing.&lt;/P&gt;
&lt;PRE&gt;815   data _null_;
816     do BDATE = '34624','34325','37432','34701' ;
817       SASDATE=input(BDATE,32.)+'30DEC1899'd ;
818       put bdate= $quote. sasdate= yymmdd10. ;
819     end;
820   run;

BDATE="34624" SASDATE=1994-10-17
BDATE="34325" SASDATE=1993-12-22
BDATE="37432" SASDATE=2002-06-25
BDATE="34701" SASDATE=1995-01-02
&lt;/PRE&gt;
&lt;P&gt;Once you have an actual date value your expression should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;firm_age= log(1+(2020 - year (SASDATE)));&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 01 Feb 2021 13:47:19 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-02-01T13:47:19Z</dc:date>
    <item>
      <title>Converting date to number forth and back</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-date-to-number-forth-and-back/m-p/715730#M221104</link>
      <description>&lt;P&gt;Hi SAS Users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I import data, I forget to format the data for the value BDATE, the raw data is as below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Type         BDATE
134495     17/10/1994
134625     22/12/1993
13811D     25/06/2002
149482     2/01/1995

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And because of importing from excel file to sas7bdat,&amp;nbsp; the data &lt;STRONG&gt;now&lt;/STRONG&gt; is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Type           BDATE
134495         34624
134625         34325
13811D         37432
149482         34701
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now I want to calculate&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;firm_age= log(1+(2020 - year (BDATE))); from the dataset &lt;STRONG&gt;now.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please help me to sort it out?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks and warm regards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 08:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-date-to-number-forth-and-back/m-p/715730#M221104</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-02-01T08:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Converting date to number forth and back</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-date-to-number-forth-and-back/m-p/715733#M221105</link>
      <description>&lt;P&gt;Add&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'30dec1899'd&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(called a "date literal", which is a special form of a numeric constant) to these values, and apply a date format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Background: SAS counts dates as days, with 1960-01-01 as day zero, while Excel starts with 1900-01-01 as day 1. Since Excel also (wrongfully) considers 1900 a leapyear, we have to go back an additional day.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 08:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-date-to-number-forth-and-back/m-p/715733#M221105</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-01T08:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Converting date to number forth and back</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-date-to-number-forth-and-back/m-p/715748#M221109</link>
      <description>&lt;P&gt;&amp;nbsp;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;
&lt;P&gt;Thank you for your explanation, could you please adding the code to extract the year or else, I do not know how to create the code to convert from number to date and retrieve the year from it. And I do not know how to add&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'30dec1899'd&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to the code as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks and warmest regards.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 11:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-date-to-number-forth-and-back/m-p/715748#M221109</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-02-01T11:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Converting date to number forth and back</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-date-to-number-forth-and-back/m-p/715762#M221112</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var = var + '30dec1899'd;
format var yymmdd10.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just a simple addition, and assignment of a date format.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 12:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-date-to-number-forth-and-back/m-p/715762#M221112</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-01T12:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: Converting date to number forth and back</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-date-to-number-forth-and-back/m-p/715774#M221120</link>
      <description>&lt;P&gt;Typically this happens when the column in excel has mixed numeric (SAS and Excel store dates as numbers) and character values. So SAS defines the variable as character and the date values get stored as digit strings that represent the number that Excel uses for the date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you probably need to fist convert BDATE into a number and then add (the negative number) '30DEC1899'D to convert the number to a SAS date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SASDATE=input(BDATE,32.)+'30DEC1899'd ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example using the strings from your posted listing.&lt;/P&gt;
&lt;PRE&gt;815   data _null_;
816     do BDATE = '34624','34325','37432','34701' ;
817       SASDATE=input(BDATE,32.)+'30DEC1899'd ;
818       put bdate= $quote. sasdate= yymmdd10. ;
819     end;
820   run;

BDATE="34624" SASDATE=1994-10-17
BDATE="34325" SASDATE=1993-12-22
BDATE="37432" SASDATE=2002-06-25
BDATE="34701" SASDATE=1995-01-02
&lt;/PRE&gt;
&lt;P&gt;Once you have an actual date value your expression should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;firm_age= log(1+(2020 - year (SASDATE)));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Feb 2021 13:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-date-to-number-forth-and-back/m-p/715774#M221120</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-01T13:47:19Z</dc:date>
    </item>
  </channel>
</rss>

