<?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: Change DATETIME to DATE9. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Change-DATETIME-to-DATE9/m-p/757186#M239102</link>
    <description>Show the log from the prior set of code as well - I suspect there's an error that needs to be fixed first. &lt;BR /&gt;My guess is that date_discharged is character, not datetime but not sure. &lt;BR /&gt;</description>
    <pubDate>Tue, 27 Jul 2021 17:14:05 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-07-27T17:14:05Z</dc:date>
    <item>
      <title>Change DATETIME to DATE9.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-DATETIME-to-DATE9/m-p/757182#M239100</link>
      <description>&lt;P&gt;I have this dataset and I there is a variable that is in the DATETIME format and I want it in the DATE9. format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;set casesdat.cases;&lt;BR /&gt;discharge = DatePart(Date_Discharged);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data b;&lt;BR /&gt;set a;&lt;BR /&gt;format discharge date9.;&lt;BR /&gt;where '01jan2020'd &amp;lt;= discharge &amp;lt;= '20dec2020'd;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The errors that come up:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot (2).png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/61908iB9A4C180599D6F28/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot (2).png" alt="Screenshot (2).png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used a libname statement to read in the dataset and I double checked that the variables are in the right format with a proc contents.&amp;nbsp;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 17:02:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-DATETIME-to-DATE9/m-p/757182#M239100</guid>
      <dc:creator>scolitti1</dc:creator>
      <dc:date>2021-07-27T17:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Change DATETIME to DATE9.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-DATETIME-to-DATE9/m-p/757186#M239102</link>
      <description>Show the log from the prior set of code as well - I suspect there's an error that needs to be fixed first. &lt;BR /&gt;My guess is that date_discharged is character, not datetime but not sure. &lt;BR /&gt;</description>
      <pubDate>Tue, 27 Jul 2021 17:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-DATETIME-to-DATE9/m-p/757186#M239102</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-27T17:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Change DATETIME to DATE9.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-DATETIME-to-DATE9/m-p/757187#M239103</link>
      <description>&lt;P&gt;You are getting these errors because variable DISCHARGE is character, it is not numeric, and so the formatting and WHERE statement will not work (these are expecting numeric values)&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 17:14:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-DATETIME-to-DATE9/m-p/757187#M239103</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-27T17:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: Change DATETIME to DATE9.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-DATETIME-to-DATE9/m-p/757188#M239104</link>
      <description>You should specify the date9. format in the first data step - see below. Also, I think you can do the where clause in the same data step as well.&lt;BR /&gt;&lt;BR /&gt;data a;&lt;BR /&gt;set casesdat.cases;&lt;BR /&gt;format discharge date9.;&lt;BR /&gt;discharge = DatePart(Date_Discharged);&lt;BR /&gt;&lt;BR /&gt;where '01jan2020'd &amp;lt;= discharge &amp;lt;= '20dec2020'd;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Jul 2021 17:14:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-DATETIME-to-DATE9/m-p/757188#M239104</guid>
      <dc:creator>Windata</dc:creator>
      <dc:date>2021-07-27T17:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Change DATETIME to DATE9.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-DATETIME-to-DATE9/m-p/757189#M239105</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/390836"&gt;@Windata&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;You should specify the date9. format in the first data step - see below. Also, I think you can do the where clause in the same data step as well.&lt;BR /&gt;&lt;BR /&gt;data a;&lt;BR /&gt;set casesdat.cases;&lt;BR /&gt;format discharge date9.;&lt;BR /&gt;discharge = DatePart(Date_Discharged);&lt;BR /&gt;&lt;BR /&gt;where '01jan2020'd &amp;lt;= discharge &amp;lt;= '20dec2020'd;&lt;BR /&gt;run;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You cannot reference the derived variable in the WHERE clause.&amp;nbsp; The where clause filters the data on the way into the data step, so it happens before DISCHARGE is created.&lt;/P&gt;
&lt;P&gt;You could use a subsetting IF instead.&lt;/P&gt;
&lt;P&gt;Or reference the original variable in the WHERE clause.&amp;nbsp; Either using appropriate datetime literals or using the DATEPART() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if '01jan2020'd &amp;lt;= discharge &amp;lt;= '20dec2020'd;
where '01jan2020:00:00'dt &amp;lt;= Date_discharged &amp;lt; '21dec2020:00:00'dt;
where '01jan2020'd &amp;lt;= datepart(Date_discharged) &amp;lt;= '20dec2020'd;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Jul 2021 17:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-DATETIME-to-DATE9/m-p/757189#M239105</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-27T17:29:36Z</dc:date>
    </item>
  </channel>
</rss>

