<?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: Formatting date-time variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Formatting-date-time-variables/m-p/543341#M150195</link>
    <description>&lt;P&gt;Prevention may be easier than correction. Go back to Excel. Make sure the entire column is formatted the same (highlight the column and set the display using the format cells).Save the file as CSV. Use Proc Import with a large value for the guessingrows option. This option examines many more rows of data before assigning the variable properties.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Examine the log. You will find datastep code to read the CSV file. If the informat for the variable is character you can 1) copy the code from the log to the editor and 2) set the desired informat. Save and rerun the data step code. If you have someone entering blank field values as shown you may want to use the ? or ?? informat modifier to prevent some of the invalid data messages that will occur if you actually have _/__/___ type data values. The ?? suppresses both the invalid data message and the display of the input data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have read other spreadsheets of similar format then do the save as CSV, change the name in the INFILE and possibly the name of the output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have had users with Excel manage to create text values that looked like dates or datetimes that were mixed in with actual Excel dates or date time values. The CSV would likely show the text versions in quotes but the data step will read both correctly (unless the text value represents an invalid date time like 31 November...).&lt;/P&gt;</description>
    <pubDate>Thu, 14 Mar 2019 22:25:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-03-14T22:25:05Z</dc:date>
    <item>
      <title>Formatting date-time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-date-time-variables/m-p/543339#M150194</link>
      <description>&lt;P&gt;Hello there,&lt;/P&gt;&lt;P&gt;I am having trouble to find the right date/time format for the character variable (or_arrival_event) in the attached SAS data file.&lt;/P&gt;&lt;P&gt;I use the following code to convert the field into a SAS date/time field but even though the&amp;nbsp;code does not yield any ERROR message it produces the wrong date/times:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if or_arrival_event in ('__/__/__ __:__') then or_arrival_event=' ';&lt;BR /&gt;or_arrival_datetime=input(or_arrival_event,anydtdtm.);&lt;BR /&gt;format or_arrival_datetime datetime15.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Recep&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: Originally the data was in Excel and the field was numeric with Excel's date/time formatting. After I import it to SAS via PROC IMPORT the field's type became character probably because of the blank values (__/__/__ __:__).&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 21:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-date-time-variables/m-p/543339#M150194</guid>
      <dc:creator>Recep</dc:creator>
      <dc:date>2019-03-14T21:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting date-time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-date-time-variables/m-p/543341#M150195</link>
      <description>&lt;P&gt;Prevention may be easier than correction. Go back to Excel. Make sure the entire column is formatted the same (highlight the column and set the display using the format cells).Save the file as CSV. Use Proc Import with a large value for the guessingrows option. This option examines many more rows of data before assigning the variable properties.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Examine the log. You will find datastep code to read the CSV file. If the informat for the variable is character you can 1) copy the code from the log to the editor and 2) set the desired informat. Save and rerun the data step code. If you have someone entering blank field values as shown you may want to use the ? or ?? informat modifier to prevent some of the invalid data messages that will occur if you actually have _/__/___ type data values. The ?? suppresses both the invalid data message and the display of the input data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have read other spreadsheets of similar format then do the save as CSV, change the name in the INFILE and possibly the name of the output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have had users with Excel manage to create text values that looked like dates or datetimes that were mixed in with actual Excel dates or date time values. The CSV would likely show the text versions in quotes but the data step will read both correctly (unless the text value represents an invalid date time like 31 November...).&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 22:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-date-time-variables/m-p/543341#M150195</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-14T22:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting date-time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-date-time-variables/m-p/543421#M150213</link>
      <description>&lt;P&gt;CSV and data step.&lt;/P&gt;
&lt;P&gt;CSV and data step.&lt;/P&gt;
&lt;P&gt;CSV and data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I tell you three times is the truth.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Excel files are not suited for a reliable import of data into SAS (or any other table-oriented data processing system) as Excel has no concept of fixed column attributes, and so all software that reads spreadsheets has to guess those attributes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See Maxims 14, 17, 22, 27, 31.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 06:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-date-time-variables/m-p/543421#M150213</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-15T06:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting date-time variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-date-time-variables/m-p/543590#M150296</link>
      <description>&lt;P&gt;Thanks a lot for your response! I think converting the Excel file to .csv resolved all the problem. Though just in case I used the "guessingrows" options which it helped.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 16:57:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-date-time-variables/m-p/543590#M150296</guid>
      <dc:creator>Recep</dc:creator>
      <dc:date>2019-03-15T16:57:02Z</dc:date>
    </item>
  </channel>
</rss>

