<?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: Input Function for Date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Input-Function-for-Date/m-p/867271#M342514</link>
    <description>&lt;P&gt;If you have COLUMN in an Excel spreadsheet that is "&lt;SPAN&gt;a mixture of dates and other information" and that means both numbers and character strings then SAS will have to create a character VARIABLE to store the information it reads from that column.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;When it does that it converts the NUMBERS that Excel uses to store dates as a digit string.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So to convert those digit strings into a SAS date value you will need to first convert them into a number and then modify the number to account for the difference in how Excel and SAS number dates.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set name;
  if lengthn(field1) in (1:5) then new_date_field=input(field1,??5.)+'30DEC1899'd;
  format new_date_field yymmdd10.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Mar 2023 17:53:24 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-03-30T17:53:24Z</dc:date>
    <item>
      <title>Input Function for Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-Function-for-Date/m-p/867210#M342497</link>
      <description>&lt;DIV class=""&gt;
&lt;DIV class=""&gt;
&lt;DIV class=""&gt;
&lt;DIV class=""&gt;
&lt;P class=""&gt;Hi I'm back again with some more date questions since I can't seem to ever do anything right with them.&lt;/P&gt;
&lt;P class=""&gt;So I have a field that is a mixture of dates and other information that im importing from excel. I'm sorting it by a case statement then doing a data step to reformat it and I'm just getting back nulls when I try and turn this characters into dates.&lt;/P&gt;
&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=""&gt;Code:&lt;/P&gt;
&lt;P class=""&gt;proc sql;&lt;BR /&gt;create table test as&lt;BR /&gt;select *&lt;BR /&gt;, case when length(field1) &amp;lt;= 5 then field1 end as new_date_field&lt;BR /&gt;from work.name;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P class=""&gt;data test2;&lt;BR /&gt;set test1;&lt;BR /&gt;format var1 date9.;&lt;BR /&gt;var1= input(new_date_field,yymmdd12.);&lt;BR /&gt;run;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 30 Mar 2023 12:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-Function-for-Date/m-p/867210#M342497</guid>
      <dc:creator>margnotis</dc:creator>
      <dc:date>2023-03-30T12:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Input Function for Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-Function-for-Date/m-p/867238#M342498</link>
      <description>&lt;P&gt;I moved your question to its own thread. Please do not hijack other's threads for your questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your CASE will populate new_date_field only when theres less than 6 characters in field1, but then you try to use an informat with a width of 12. That won't work.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 12:58:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-Function-for-Date/m-p/867238#M342498</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-30T12:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: Input Function for Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-Function-for-Date/m-p/867271#M342514</link>
      <description>&lt;P&gt;If you have COLUMN in an Excel spreadsheet that is "&lt;SPAN&gt;a mixture of dates and other information" and that means both numbers and character strings then SAS will have to create a character VARIABLE to store the information it reads from that column.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;When it does that it converts the NUMBERS that Excel uses to store dates as a digit string.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So to convert those digit strings into a SAS date value you will need to first convert them into a number and then modify the number to account for the difference in how Excel and SAS number dates.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set name;
  if lengthn(field1) in (1:5) then new_date_field=input(field1,??5.)+'30DEC1899'd;
  format new_date_field yymmdd10.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 17:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-Function-for-Date/m-p/867271#M342514</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-30T17:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Input Function for Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-Function-for-Date/m-p/867276#M342519</link>
      <description>&lt;P&gt;30Dec1899 ?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Gotta love the persistence of old bugs.&amp;nbsp; And Microsoft doesn't even call it a leap year bug, they just say they designed Excel to be compatible with Lotus 1-2-3...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/office/troubleshoot/excel/wrongly-assumes-1900-is-leap-year" target="_blank"&gt;https://learn.microsoft.com/en-us/office/troubleshoot/excel/wrongly-assumes-1900-is-leap-year&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 16:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-Function-for-Date/m-p/867276#M342519</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-30T16:31:02Z</dc:date>
    </item>
  </channel>
</rss>

