<?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 dates in DS2 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-in-DS2/m-p/463758#M284994</link>
    <description>&lt;P&gt;Thanks very much, Patrick! As you said, to_data() function is sufficient to compare the dates without any more conversion. It works great!&lt;/P&gt;</description>
    <pubDate>Mon, 21 May 2018 11:54:10 GMT</pubDate>
    <dc:creator>lruan1</dc:creator>
    <dc:date>2018-05-21T11:54:10Z</dc:date>
    <item>
      <title>Comparing dates in DS2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-in-DS2/m-p/463437#M284992</link>
      <description>&lt;P&gt;Hi all, I am brand new to DS2 and I wonder if you can give any suggestions on comparing dates. The logic is pretty straightforward. I convert the string to the date and then convert to the double for comparing purpose. Everything is fine till I change the hard coded '&lt;SPAN&gt;2018-06-04' with a variable 'date_String'. Then the date conversion step fails. Do I miss anything? Thanks very much!&amp;nbsp;&lt;/SPAN&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;method run();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dcl date dt1 dt2 dt3;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dcl double ddt1 ddt2 ddt3 we;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dcl varchar(10) date_String;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date_String = '2018-06-04'&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dt1 = date date_String;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dt2 = date '2018-06-05';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dt3 = date '2019-01-04';&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ddt1 = to_double(dt1);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ddt2 = to_double(dt2);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ddt3 = to_double(dt3);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;put ddt1= ddt2= ddt3=;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if ddt1 &amp;lt; ddt3 AND ddt2 &amp;lt; ddt3 then we = 5.3;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;put we=;&lt;BR /&gt;end;&lt;BR /&gt;enddata;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 20:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-in-DS2/m-p/463437#M284992</guid>
      <dc:creator>lruan1</dc:creator>
      <dc:date>2018-05-18T20:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing dates in DS2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-in-DS2/m-p/463475#M284993</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/182149"&gt;@lruan1&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;You need to use the to_date() function.&lt;/P&gt;
&lt;PRE&gt;      dcl varchar(10) date_String;
      date_String = '2018-06-04';
      Dt1 = to_date(date_String);
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand why you believe you have to convert the Date type to Double for comparison. Using Date should be more than fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May be this link will be helpful to you: &lt;A href="http://support.sas.com/kb/51/769.html&amp;nbsp;" target="_blank"&gt;http://support.sas.com/kb/51/769.html&amp;nbsp;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 02:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-in-DS2/m-p/463475#M284993</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-05-19T02:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing dates in DS2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-in-DS2/m-p/463758#M284994</link>
      <description>&lt;P&gt;Thanks very much, Patrick! As you said, to_data() function is sufficient to compare the dates without any more conversion. It works great!&lt;/P&gt;</description>
      <pubDate>Mon, 21 May 2018 11:54:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-in-DS2/m-p/463758#M284994</guid>
      <dc:creator>lruan1</dc:creator>
      <dc:date>2018-05-21T11:54:10Z</dc:date>
    </item>
  </channel>
</rss>

