<?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: Comparing a SAS Datetime value to a SAS Date Value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638535#M189894</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24237"&gt;@elwayfan446&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;As I mentioned, when I do that it gives me a result in a sas date format.&amp;nbsp; I can't (or don't know how) to change the date to an actual mmddyy10. format inside the database, not just simply the label.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Does the comment "i&lt;STRONG&gt;nside the database"&lt;/STRONG&gt; imply that your data resides in an external database such as Oracle, DB2 or SQL Server?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so you need to provide a lot more detail such as how you are connecting to the database and which one as that can have a serious affect on date related issues.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Apr 2020 22:49:42 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-04-08T22:49:42Z</dc:date>
    <item>
      <title>Comparing a SAS Datetime value to a SAS Date Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638517#M189880</link>
      <description>&lt;P&gt;I am trying to do a very basic comparison in sas and for the life of me can't figure out what I am doing wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two variables I want to compare... one is a datetime and the other is just a date.&amp;nbsp; I need to run a query where the date variable is less that the datetime variable, but because they are not both one or the other, it doesn't compare it properly.&amp;nbsp; I can't simply format it, I need it to be the actual format of the variable in the database in order to compare.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;where mmddyy10. &amp;lt; datetime20.&lt;/PRE&gt;&lt;P&gt;I just can't figure out how to convert one or the other.&amp;nbsp; If I use datepart() on the datetime value, I get a SAS date in which I still can't compare to a date that is formatted in mmddyy10. and I can't figure out how to convert that sas date into a mmddyy10. either.&amp;nbsp; If I try to use dhms() on the date variable, I also get a sas value that is not comparable.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:05:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638517#M189880</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-04-08T22:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a SAS Datetime value to a SAS Date Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638518#M189881</link>
      <description>&lt;P&gt;What are the TYPES (not formats) of each variable you're trying to compare?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24237"&gt;@elwayfan446&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to do a very basic comparison in sas and for the life of me can't figure out what I am doing wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two variables I want to compare... one is a datetime and the other is just a date.&amp;nbsp; I need to run a query where the date variable is less that the datetime variable, but because they are not both one or the other, it doesn't compare it properly.&amp;nbsp; I can't simply format it, I need it to be the actual format of the variable in the database in order to compare.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;where mmddyy10. &amp;lt; datetime20.&lt;/PRE&gt;
&lt;P&gt;I just can't figure out how to convert one or the other.&amp;nbsp; If I use datepart() on the datetime value, I get a SAS date in which I still can't compare to a date that is formatted in mmddyy10. and I can't figure out how to convert that sas date into a mmddyy10. either.&amp;nbsp; If I try to use dhms() on the date variable, I also get a sas value that is not comparable.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638518#M189881</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-04-08T22:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a SAS Datetime value to a SAS Date Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638519#M189882</link>
      <description>&lt;P&gt;You can extract the date portion of a Datetime variable with the DATEPART function:&lt;/P&gt;
&lt;PRE&gt;where datevar &amp;lt; datepart (datetimevar)&lt;/PRE&gt;
&lt;P&gt;The display formats have nothing to do with the numeric value comparisons. The functions and comparisons use the internal values.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638519#M189882</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-08T22:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a SAS Datetime value to a SAS Date Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638525#M189884</link>
      <description>&lt;P&gt;Both are are already date types.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="elwayfan446_1-1586384791506.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38066i465D7B74FCC6346F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="elwayfan446_1-1586384791506.png" alt="elwayfan446_1-1586384791506.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am running a query where I want to find records where the date_contract_expires &amp;lt; date_contract_accepted&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638525#M189884</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-04-08T22:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a SAS Datetime value to a SAS Date Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638526#M189885</link>
      <description>&lt;P&gt;As I mentioned, when I do that it gives me a result in a sas date format.&amp;nbsp; I can't (or don't know how) to change the date to an actual mmddyy10. format inside the database, not just simply the label.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638526#M189885</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-04-08T22:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a SAS Datetime value to a SAS Date Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638531#M189890</link>
      <description>&lt;P&gt;Formats don't matter for comparison, SAS will compare the underlying values. There should be no need to set the format of the variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If you want to format the date after the fact you can always do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data_new = datepart(datetimeVar);
format date_new mmddyys10.;

if date_new &amp;gt; date_old then ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24237"&gt;@elwayfan446&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;As I mentioned, when I do that it gives me a result in a sas date format.&amp;nbsp; I can't (or don't know how) to change the date to an actual mmddyy10. format inside the database, not just simply the label.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What are you using to show types/formats/ SAS only has two types, num/char, so I'm confused as to where it would say 'Date'.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638531#M189890</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-04-08T22:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a SAS Datetime value to a SAS Date Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638532#M189891</link>
      <description>&lt;P&gt;SAS stores both Date and DateTime values as numbers in a numerical variable (no special data type like in databases).&lt;/P&gt;
&lt;P&gt;A SAS Date value is the count of Days since 1/1/1960&lt;/P&gt;
&lt;P&gt;A SAS DateTime value is the count of Seconds since 1/1/1960&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A SAS Format is used for Display ("print") of values so they become human readable. A SAS Format does not change the value as such.&lt;/P&gt;
&lt;P&gt;There are formats for DateTime values and there are formats for Date values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Calculations and comparisons are done using the Internal values (the counts of days or seconds). Formats are of no relevance here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The datepart() function converts a SAS DateTime value to a SAS Date value (basically: Integer portion of a division of the DateTime value through seconds of a day).&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638532#M189891</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-04-08T22:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a SAS Datetime value to a SAS Date Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638534#M189893</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24237"&gt;@elwayfan446&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Both are are already date types.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="elwayfan446_1-1586384791506.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38066i465D7B74FCC6346F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="elwayfan446_1-1586384791506.png" alt="elwayfan446_1-1586384791506.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am running a query where I want to find records where the date_contract_expires &amp;lt; date_contract_accepted&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No they aren't Date_contract_accepted is DATETIME. The units used in datetime values are seconds. The unit used in Dates are Days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638534#M189893</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-08T22:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a SAS Datetime value to a SAS Date Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638535#M189894</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24237"&gt;@elwayfan446&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;As I mentioned, when I do that it gives me a result in a sas date format.&amp;nbsp; I can't (or don't know how) to change the date to an actual mmddyy10. format inside the database, not just simply the label.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Does the comment "i&lt;STRONG&gt;nside the database"&lt;/STRONG&gt; imply that your data resides in an external database such as Oracle, DB2 or SQL Server?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so you need to provide a lot more detail such as how you are connecting to the database and which one as that can have a serious affect on date related issues.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638535#M189894</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-08T22:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a SAS Datetime value to a SAS Date Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638536#M189895</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where date_contract_expires &amp;lt; datepart(date_contract_accepted);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If this does not work, post your log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638536#M189895</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-04-08T22:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing a SAS Datetime value to a SAS Date Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638537#M189896</link>
      <description>&lt;P&gt;My problem was that I was getting what I thought was an incorrect result based on the actual comparison of the values.&amp;nbsp; After digging through my code and all of the relevant dates I had and also thinking more about what you guys were telling me, I realized what I did wrong.&amp;nbsp; If nothing else, your responses got my mind pointed in the right direction to figure this out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for all the help.&amp;nbsp; At least this thread will help someone else when they have questions regarding the formatting versus the actual value stored in the dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 22:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-a-SAS-Datetime-value-to-a-SAS-Date-Value/m-p/638537#M189896</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-04-08T22:53:18Z</dc:date>
    </item>
  </channel>
</rss>

