<?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: compare date to datetime in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689640#M24677</link>
    <description>Hi ballardw&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Examdate is&lt;BR /&gt;Num&lt;BR /&gt;Length 8&lt;BR /&gt;MMDDYY10&lt;BR /&gt;&lt;BR /&gt;But visitdatetime is&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Char&lt;BR /&gt;Length 500&lt;BR /&gt;$500.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I already tried&lt;BR /&gt;&lt;BR /&gt;New_date= datepart(visitdatetime) but I get a bunch of error messages like this&lt;BR /&gt;&lt;BR /&gt;Invalid numeric data, vistdatetime='2020-09-14 12:02:52' , at line 1278 column 21&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Really appreciate your help!&lt;BR /&gt;&lt;BR /&gt;Margaret&lt;BR /&gt;</description>
    <pubDate>Wed, 07 Oct 2020 17:29:13 GMT</pubDate>
    <dc:creator>urban58</dc:creator>
    <dc:date>2020-10-07T17:29:13Z</dc:date>
    <item>
      <title>compare date to datetime</title>
      <link>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689586#M24662</link>
      <description>&lt;P&gt;How do I extract the date and compare these 2 dates?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;9/14/2020&lt;/P&gt;&lt;P&gt;2020-09-14 12:02:52&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried the following unsuccessfully to extract the date only&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;date_new = datepart(dt_var);
format date_new mmddyy10.;

proc print;
where date_new ^= dt_var;
run;&lt;/LI-CODE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Margaret&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 15:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689586#M24662</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2020-10-07T15:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: compare date to datetime</title>
      <link>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689597#M24665</link>
      <description>&lt;P&gt;This needs further explanation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you mean that you have both dates and datetime values in the same column (as your small example implies)? Or are they different variables (if so, what are the variable names)?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 15:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689597#M24665</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-07T15:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: compare date to datetime</title>
      <link>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689614#M24668</link>
      <description>different variables</description>
      <pubDate>Wed, 07 Oct 2020 16:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689614#M24668</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2020-10-07T16:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: compare date to datetime</title>
      <link>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689615#M24669</link>
      <description>&lt;P&gt;Since your example extracts the datepart from a datetime variable then you have change the units and as such will almost always be less than the datetime value (at least for dates and date times since 1960).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Typically the comparison between a date and datetime would be more&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;datevar le datepart(datetimevar)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or similar. But that is pretty meaningless if the datevar is created from datetimevar as you show as that would always be equal.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 16:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689615#M24669</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-07T16:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: compare date to datetime</title>
      <link>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689617#M24670</link>
      <description>but there are many dates and datetimes that are not, e.g.&lt;BR /&gt;examdate visitdatetime&lt;BR /&gt;9/14/2020 2020-09-15 12:02:52&lt;BR /&gt;9/02/2020 2020-08-15 12:12:52&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Oct 2020 16:13:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689617#M24670</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2020-10-07T16:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: compare date to datetime</title>
      <link>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689631#M24674</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/322157"&gt;@urban58&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;but there are many dates and datetimes that are not, e.g.&lt;BR /&gt;examdate visitdatetime&lt;BR /&gt;9/14/2020 2020-09-15 12:02:52&lt;BR /&gt;9/02/2020 2020-08-15 12:12:52&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are not what?&lt;/P&gt;
&lt;P&gt;The only example you provided earlier had the date created from the datetime value.&lt;/P&gt;
&lt;P&gt;So the comparison would involve&lt;/P&gt;
&lt;P&gt;examdate &amp;lt;comparison operator&amp;gt; datepart(visitdatetime)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 17:16:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689631#M24674</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-07T17:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: compare date to datetime</title>
      <link>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689640#M24677</link>
      <description>Hi ballardw&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Examdate is&lt;BR /&gt;Num&lt;BR /&gt;Length 8&lt;BR /&gt;MMDDYY10&lt;BR /&gt;&lt;BR /&gt;But visitdatetime is&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Char&lt;BR /&gt;Length 500&lt;BR /&gt;$500.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I already tried&lt;BR /&gt;&lt;BR /&gt;New_date= datepart(visitdatetime) but I get a bunch of error messages like this&lt;BR /&gt;&lt;BR /&gt;Invalid numeric data, vistdatetime='2020-09-14 12:02:52' , at line 1278 column 21&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Really appreciate your help!&lt;BR /&gt;&lt;BR /&gt;Margaret&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Oct 2020 17:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689640#M24677</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2020-10-07T17:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: compare date to datetime</title>
      <link>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689654#M24680</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/322157"&gt;@urban58&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi ballardw&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Examdate is&lt;BR /&gt;Num&lt;BR /&gt;Length 8&lt;BR /&gt;MMDDYY10&lt;BR /&gt;&lt;BR /&gt;But visitdatetime is&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Char&lt;BR /&gt;Length 500&lt;BR /&gt;$500.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I already tried&lt;BR /&gt;&lt;BR /&gt;New_date= datepart(visitdatetime) but I get a bunch of error messages like this&lt;BR /&gt;&lt;BR /&gt;Invalid numeric data, vistdatetime='2020-09-14 12:02:52' , at line 1278 column 21&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Really appreciate your help!&lt;BR /&gt;&lt;BR /&gt;Margaret&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That means that your variable VISTdatetime is not a datatime value. It is character. So the first thing is to either convert the string into a datetime value in the comparson or create a new variable with the datetime (if you need it as such later).&lt;/P&gt;
&lt;P&gt;Here is an example of creating an actual datetime value from the string.&lt;/P&gt;
&lt;PRE&gt;data example;
  x ='       2020-09-14 12:02:52';
  y = input(strip(x),e8601dt.);
  format y datetime.;
run;&lt;/PRE&gt;
&lt;P&gt;The Strip function is included because you character variable is 500 (!) characters long and strip will remove leading and trailing spaces if present before trying to convert the value. The E8601dt informat will read values as you show. The format statement is to display the new value with a different display format so you can see that the converted value is treated as needed.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 18:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689654#M24680</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-07T18:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: compare date to datetime</title>
      <link>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689728#M24687</link>
      <description>Thank you so much for the explanation as well as the code to convert it to a datetime variable, you wouldn't believe how long I worked on it.&lt;BR /&gt;Margaret&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Oct 2020 20:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/compare-date-to-datetime/m-p/689728#M24687</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2020-10-07T20:36:13Z</dc:date>
    </item>
  </channel>
</rss>

