<?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: convert variable of Char and numeric to date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-of-Char-and-numeric-to-date/m-p/283872#M57883</link>
    <description>&lt;P&gt;The problem is who ever created the Excel file didn't set what appears to be a date type for the entire column. If you are going to work with similar data in the future it should be addressed before importing into SAS to reduce problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the values are in at least two forms you will need multiple approaches to dealing with this.&lt;/P&gt;
&lt;P&gt;First, the displayed values of your example are in mmddyy10. form not year first as yymmdd would imply.&lt;/P&gt;
&lt;P&gt;The second is you need to adjust the Excel date value to match SAS. The are&amp;nbsp;both numbers of days but the value bases are notably different.&lt;/P&gt;
&lt;P&gt;If you have other date formats you'll need to modify this for those values.&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; index(var,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'/'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;) &amp;gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;0&lt;/FONT&gt; &lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;then&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; var_form=input(var, &lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;anydtdte.&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;else&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt; var_form = input(var,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;best8.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt;) +&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;'30DEC1899'd&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Jul 2016 19:24:38 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-07-12T19:24:38Z</dc:date>
    <item>
      <title>convert variable of Char and numeric to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-of-Char-and-numeric-to-date/m-p/283867#M57881</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;i have imported a DS from excel. some of the variables are made up of numeric values and char. I have attached it as it appears in excel. When i import it into SAS, it becomes a Char variable. I have no idea how to convert it in a SAS date so i can get the year of it etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i used the following code in my data step but the out was simple "." for every value&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var_form=input(var,yymmdd10.);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;format var_form worddate.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help? i have a fewe variables like this and its driving me crazy. i can fix it in excel but need to do it in sas.&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12746i880402DEF57FE1FC/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="sas_c.PNG" title="sas_c.PNG" /&gt;</description>
      <pubDate>Tue, 12 Jul 2016 18:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-of-Char-and-numeric-to-date/m-p/283867#M57881</guid>
      <dc:creator>jcurran1289</dc:creator>
      <dc:date>2016-07-12T18:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: convert variable of Char and numeric to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-of-Char-and-numeric-to-date/m-p/283872#M57883</link>
      <description>&lt;P&gt;The problem is who ever created the Excel file didn't set what appears to be a date type for the entire column. If you are going to work with similar data in the future it should be addressed before importing into SAS to reduce problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the values are in at least two forms you will need multiple approaches to dealing with this.&lt;/P&gt;
&lt;P&gt;First, the displayed values of your example are in mmddyy10. form not year first as yymmdd would imply.&lt;/P&gt;
&lt;P&gt;The second is you need to adjust the Excel date value to match SAS. The are&amp;nbsp;both numbers of days but the value bases are notably different.&lt;/P&gt;
&lt;P&gt;If you have other date formats you'll need to modify this for those values.&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; index(var,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'/'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;) &amp;gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;0&lt;/FONT&gt; &lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;then&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; var_form=input(var, &lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;anydtdte.&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;else&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt; var_form = input(var,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;best8.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt;) +&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;'30DEC1899'd&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 19:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-of-Char-and-numeric-to-date/m-p/283872#M57883</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-12T19:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: convert variable of Char and numeric to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-of-Char-and-numeric-to-date/m-p/283874#M57885</link>
      <description>&lt;P&gt;Try using MMDDYY10. as teh INFORMAT in the INPUT function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In general, the INFORMAT must match the format of the data you wish to convert.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suggest reviewing the details of the ANYDATE informat as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTH - Jack&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 19:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-of-Char-and-numeric-to-date/m-p/283874#M57885</guid>
      <dc:creator>sh0e</dc:creator>
      <dc:date>2016-07-12T19:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: convert variable of Char and numeric to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-variable-of-Char-and-numeric-to-date/m-p/285825#M58510</link>
      <description>&lt;P&gt;Thanks. My mistake before. thanks very much for the help!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 14:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-variable-of-Char-and-numeric-to-date/m-p/285825#M58510</guid>
      <dc:creator>jcurran1289</dc:creator>
      <dc:date>2016-07-20T14:26:40Z</dc:date>
    </item>
  </channel>
</rss>

