<?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: proc sql where statement in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-where-statement/m-p/721329#M38224</link>
    <description>&lt;P&gt;Are FROM and TO character strings like '&lt;SPAN&gt;20081231'&amp;nbsp;&lt;/SPAN&gt;or numbers like&amp;nbsp;&lt;SPAN&gt;20,081,231?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If they are strings then generated SAS code in the WHERE clause needs to contain with single or double quotes, but your example code is going generate both double and single quotes.&amp;nbsp; It they are numbers then you do not want any quotes.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The LE operator means less than or equal to, which you also write as &amp;lt;= .&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You do not need the CALCULATED keyword in this example if FROM is a variable that is coming from the input TABLE10.&amp;nbsp; If FROM was the name of some generated variable listed in the SELECT statement then you would need the CALCULATED keyword.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If FROM and TO are character you could keep the quotes in the macro variable:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dateproduction='20200131';
proc sql;
create table mytable as
  select *
  from table10
  where  (from le &amp;amp;DATEPRODUCTION. le to)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Or not put the quotes&amp;nbsp;in the macro variable and instead add them back into the generated code.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dateproduction=20200131;
proc sql;
create table mytable as
  select *
  from table10
  where  (from le "&amp;amp;DATEPRODUCTION." le to)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 23 Feb 2021 16:33:37 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-02-23T16:33:37Z</dc:date>
    <item>
      <title>proc sql where statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-where-statement/m-p/721317#M38222</link>
      <description>&lt;P&gt;Good morning,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found a script on our server and I am not sure how to interpret it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a simplify version of the code.&amp;nbsp; So we are trying to create a table named mytable from the contains of table10 which contains few variables , including the variable from and to.&amp;nbsp; The variable from to contains date like 20081231 to 99991231.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So suppose that we have %let dateproduction='20200131'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe the le statement means less or equal but how will work the where statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your help&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;
&lt;P&gt;proc sql;&lt;BR /&gt;create table mytable as&lt;BR /&gt;select *&lt;BR /&gt;from table10&lt;BR /&gt;where( calculated from le "&amp;amp;DATEPRODUCTION." le calculated to&lt;BR /&gt;);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 16:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-where-statement/m-p/721317#M38222</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-02-23T16:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql where statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-where-statement/m-p/721321#M38223</link>
      <description>&lt;P&gt;Do you mean you want to extract all records where &amp;amp;dateproduction is greater than or equal to variable FROM and less than or equal to variable TO?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 16:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-where-statement/m-p/721321#M38223</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-23T16:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql where statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-where-statement/m-p/721329#M38224</link>
      <description>&lt;P&gt;Are FROM and TO character strings like '&lt;SPAN&gt;20081231'&amp;nbsp;&lt;/SPAN&gt;or numbers like&amp;nbsp;&lt;SPAN&gt;20,081,231?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If they are strings then generated SAS code in the WHERE clause needs to contain with single or double quotes, but your example code is going generate both double and single quotes.&amp;nbsp; It they are numbers then you do not want any quotes.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The LE operator means less than or equal to, which you also write as &amp;lt;= .&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You do not need the CALCULATED keyword in this example if FROM is a variable that is coming from the input TABLE10.&amp;nbsp; If FROM was the name of some generated variable listed in the SELECT statement then you would need the CALCULATED keyword.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If FROM and TO are character you could keep the quotes in the macro variable:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dateproduction='20200131';
proc sql;
create table mytable as
  select *
  from table10
  where  (from le &amp;amp;DATEPRODUCTION. le to)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Or not put the quotes&amp;nbsp;in the macro variable and instead add them back into the generated code.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dateproduction=20200131;
proc sql;
create table mytable as
  select *
  from table10
  where  (from le "&amp;amp;DATEPRODUCTION." le to)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Feb 2021 16:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-where-statement/m-p/721329#M38224</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-23T16:33:37Z</dc:date>
    </item>
  </channel>
</rss>

