<?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: character date variables can be compared directly without converting numeric in Proc SQL? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/character-date-variables-can-be-compared-directly-without/m-p/322050#M71198</link>
    <description>&lt;BLOCKQUOTE&gt;But in proc sql, it seems the character date variables can be directly compared.&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You CAN compare character date variables in a data step as well as SQL, but it will be &lt;STRONG&gt;alphabetic order, not numerical/calendar order.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: The variable types must be the same in either method, SQL or data step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Jan 2017 02:41:01 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-01-03T02:41:01Z</dc:date>
    <item>
      <title>character date variables can be compared directly without converting numeric in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-date-variables-can-be-compared-directly-without/m-p/322044#M71193</link>
      <description>&lt;P&gt;when comparing date variables in data steps, we have to convert the character date variables to numeric first with input statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in proc sql, it seems the character date variables can be directly compared.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the following code, without converting to numeric, the character variables can be compared just like numeric:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
      create table lb as
      select a.*, b.visit, b.visitnum
      from lb_ as a 
            left join sv as b 
                on a.usubjid=b.usubjid and (b.svstdtc &amp;lt;=a.lbdtc &amp;lt;= b.svendtc);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does Proc Sql automatically convert the character date variables to numeric for the comparison?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2017 01:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-date-variables-can-be-compared-directly-without/m-p/322044#M71193</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2017-01-03T01:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: character date variables can be compared directly without converting numeric in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-date-variables-can-be-compared-directly-without/m-p/322046#M71195</link>
      <description>&lt;P&gt;Does compared variables have same type in both datasets ?&lt;/P&gt;
&lt;P&gt;If yes - then probably it is compared char to char.&lt;/P&gt;
&lt;P&gt;If no - are you sure you get the right results ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post sample of both datasets and their data types.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2017 02:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-date-variables-can-be-compared-directly-without/m-p/322046#M71195</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-01-03T02:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: character date variables can be compared directly without converting numeric in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-date-variables-can-be-compared-directly-without/m-p/322050#M71198</link>
      <description>&lt;BLOCKQUOTE&gt;But in proc sql, it seems the character date variables can be directly compared.&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You CAN compare character date variables in a data step as well as SQL, but it will be &lt;STRONG&gt;alphabetic order, not numerical/calendar order.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: The variable types must be the same in either method, SQL or data step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2017 02:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-date-variables-can-be-compared-directly-without/m-p/322050#M71198</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-03T02:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: character date variables can be compared directly without converting numeric in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-date-variables-can-be-compared-directly-without/m-p/322189#M71268</link>
      <description>&lt;P&gt;To expand on &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s comment:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;10Jan2017 will be before 9Jan2016 in character comparison because 1 &amp;lt; 9, first characters compared.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or Aug 10, 2016 comes before Jan 10, 2017 because A &amp;lt; J&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF your character values are in the form of YYYYMMDD and have zeroes as place holders then you would be okay as 20170110 comes after 20170109 in character comparisons. Any other character valued dates are likely to fail and some quite spectacularly.&lt;/P&gt;
&lt;P&gt;Also conversion to SAS date values will help you clean up bad dates such as Feb 30 and my favorite from an inherited data project August 67, 1985&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2017 16:17:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-date-variables-can-be-compared-directly-without/m-p/322189#M71268</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-03T16:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: character date variables can be compared directly without converting numeric in Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-date-variables-can-be-compared-directly-without/m-p/322221#M71275</link>
      <description>&lt;P&gt;Yes, my date is in yyyymmdd format (like '2015-09-03'). Now I understand why it runs okay.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did compare with converting to numeric values, and there is no difference. The key is the character date has to be in yyyymmdd format.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2017 18:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-date-variables-can-be-compared-directly-without/m-p/322221#M71275</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2017-01-03T18:19:21Z</dc:date>
    </item>
  </channel>
</rss>

