<?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 Unable to convert all character values to date format mmddyy10. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-convert-all-character-values-to-date-format-mmddyy10/m-p/946881#M370779</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I received a date variable (infection2_date) in Excel, but when I imported into SASm it showed as character fomat. I&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[infection2_date Char 10 $10. $10. infection2_date.]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ran the code below, but some dates were not successfully converted (see SAS data output).&amp;nbsp;&lt;BR /&gt;data want;&lt;BR /&gt;set test;&lt;BR /&gt;newdate = input(infection2_date,mmddyy10.);&lt;BR /&gt;format newdate mmddyy10.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone please help me with the code to convert all the dates from char values? Thanks in advance!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Infection.JPG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101071iBBBB211858DC41BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Infection.JPG" alt="Infection.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
    <pubDate>Thu, 10 Oct 2024 00:50:02 GMT</pubDate>
    <dc:creator>Denali</dc:creator>
    <dc:date>2024-10-10T00:50:02Z</dc:date>
    <item>
      <title>Unable to convert all character values to date format mmddyy10.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-convert-all-character-values-to-date-format-mmddyy10/m-p/946881#M370779</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I received a date variable (infection2_date) in Excel, but when I imported into SASm it showed as character fomat. I&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[infection2_date Char 10 $10. $10. infection2_date.]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ran the code below, but some dates were not successfully converted (see SAS data output).&amp;nbsp;&lt;BR /&gt;data want;&lt;BR /&gt;set test;&lt;BR /&gt;newdate = input(infection2_date,mmddyy10.);&lt;BR /&gt;format newdate mmddyy10.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone please help me with the code to convert all the dates from char values? Thanks in advance!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Infection.JPG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101071iBBBB211858DC41BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Infection.JPG" alt="Infection.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 00:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-convert-all-character-values-to-date-format-mmddyy10/m-p/946881#M370779</guid>
      <dc:creator>Denali</dc:creator>
      <dc:date>2024-10-10T00:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to convert all character values to date format mmddyy10.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-convert-all-character-values-to-date-format-mmddyy10/m-p/946891#M370783</link>
      <description>&lt;P&gt;Since the column in your Excel worksheet had a mix of numeric (DATE) values and CHARACTER so SAS had to make the variable it used to store the values CHARACTER (you can store numbers as character strings but not the other way around).&amp;nbsp; When it does that it stores DATE values as the digit string that represents the number that Excel uses to store the number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can modify the Excel sheet the find the cells with character strings (perhaps someone had a string in DDMMYY order that your version of Excel did not understand.&amp;nbsp; Or had an invalid date such as FEB29 on a non-leap year.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise the fix is to first convert the string into a number, then adjust for the difference in how Excel and SAS number the days.&amp;nbsp; Make sure to attach a date style format.&amp;nbsp; I would avoid using MMDDYY as displaying dates in MDY order will confuse viewers from countries that normally display dates in DMY order.&amp;nbsp; So use either DATE or YYMMDD format to avoid such confusion.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set test;
  newdate = input(infection2_date,32.) + '30DEC1899'd ;
  format newdate yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 02:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-convert-all-character-values-to-date-format-mmddyy10/m-p/946891#M370783</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-10T02:58:57Z</dc:date>
    </item>
  </channel>
</rss>

