<?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: Import a variable having different date format from xlsx file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857910#M338977</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/326318"&gt;@Himanshu4&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Please try importing first and let us know if you are facing error.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Feb 2023 00:04:34 GMT</pubDate>
    <dc:creator>Sajid01</dc:creator>
    <dc:date>2023-02-09T00:04:34Z</dc:date>
    <item>
      <title>Import a variable having different date format from xlsx file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857867#M338964</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Himanshu4_0-1675888003331.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80243i888B593361745C9F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Himanshu4_0-1675888003331.png" alt="Himanshu4_0-1675888003331.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a variable in xlsx file having different format for date variable and need to upload it in SAS and create a dataset with date format. any suggestions??&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 20:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857867#M338964</guid>
      <dc:creator>Himanshu4</dc:creator>
      <dc:date>2023-02-08T20:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: Import a variable having different date format from xlsx file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857868#M338965</link>
      <description>&lt;P&gt;Are these stored in a character variable as text strings after you import into SAS? (Please don't tell me what they are in Excel, as that is irrelevant)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If they are text, you can possibly convert them into valid dates using the &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/leforinforref/n04jh1fkv5c8zan14fhqcby7jsu4.htm" target="_self"&gt;ANYDTDTE. informat&lt;/A&gt; which guesses what the format is and can (I think) handle different formatting on different rows.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 20:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857868#M338965</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-08T20:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Import a variable having different date format from xlsx file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857906#M338976</link>
      <description>After uploading it in excel its character, however data is populating like below, means. There is no specific format. And i would need that in a date format.&lt;BR /&gt;18Jan2020&lt;BR /&gt;45677&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 08 Feb 2023 23:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857906#M338976</guid>
      <dc:creator>Himanshu4</dc:creator>
      <dc:date>2023-02-08T23:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Import a variable having different date format from xlsx file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857910#M338977</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/326318"&gt;@Himanshu4&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Please try importing first and let us know if you are facing error.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 00:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857910#M338977</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2023-02-09T00:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: Import a variable having different date format from xlsx file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857912#M338979</link>
      <description>&lt;P&gt;Try changing the column type in Excel from General (the default) to Short Date then reimport.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 00:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857912#M338979</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-02-09T00:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Import a variable having different date format from xlsx file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857930#M338980</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/326318"&gt;@Himanshu4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;After uploading it in excel its character, however data is populating like below, means. There is no specific format. And i would need that in a date format.&lt;BR /&gt;18Jan2020&lt;BR /&gt;45677&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you see both of those values in the same variable in the same dataset on different observations then your column in Excel has at least one cell that has a string in it instead of a date.&amp;nbsp; In this case it is the the string '18Jan2020'.&amp;nbsp; The other string '45677' is how SAS pulls the number that Excel uses to store the date 20JAN2025 (if it is using 1900 as the base date) or 20JAN2029 (if it is using 1904 as the base date).&lt;/P&gt;
&lt;PRE&gt;2876  data _null_;
2877  excel=45677;
2878  sas=excel+'30dec1899'd ;
2879  put excel=comma7. sas=comma7. ' -&amp;gt; ' sas date9.;
2880  sas=excel+'31dec1903'd ;
2881  put excel=comma7. sas=comma7. ' -&amp;gt; ' sas date9.;
2882
2883  run;

excel=45,677 sas=23,761  -&amp;gt; 20JAN2025
excel=45,677 sas=25,222  -&amp;gt; 20JAN2029
&lt;/PRE&gt;
&lt;P&gt;To convert both those strings into actual date values you will need to do some testing to see which you have.&lt;/P&gt;
&lt;P&gt;So you might assume that most of them were value Excel Date values and so first try to convert the 5 digit strings into dates and then when that did not work try to convert the string using the ANYDTDTE informat.&lt;/P&gt;
&lt;P&gt;So if the dataset you created from the Excel sheet is named HAVE and the column that was supposed to have date values is named DATESTRING then here is data step that will make a new numeric variable named DATENUM that has actual date values and has a format attached that will print the date values in a way that humans can understand.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  datenum = input(datestring,??32.)+'30dec1899'd;
  if missing(datenum) then datenum=input(datestring,anydtdte20.);
  format datenum date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Feb 2023 04:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857930#M338980</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-09T04:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Import a variable having different date format from xlsx file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857946#M338986</link>
      <description>&lt;P&gt;Assign a consistent date format to the whole column in Excel. Then save the spreadsheet as a csv file and read that with a data step.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 06:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-variable-having-different-date-format-from-xlsx-file/m-p/857946#M338986</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-09T06:52:33Z</dc:date>
    </item>
  </channel>
</rss>

