<?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 Conditionally Execuete Where clause in proc print in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Execuete-Where-clause-in-proc-print/m-p/876682#M346333</link>
    <description>&lt;P&gt;In the following code, I want to execute the where clause in proc print only if the macro variable 'filter' is 'y' otherwise it should not execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let target_table=&amp;amp;datasource;
%global prompt;
%filter ='y';

proc sort data= "&amp;amp;envPath/data/gb/&amp;amp;datasource" out=sorted nodupkey /*or noduprecs if sorting all vars*/;
	by &amp;amp;_field /* or list of vars */;
run; 
proc print data= sorted noobs;
	where &amp;amp;parameter_1 in ("&amp;amp;parameter_2"); /** need help here to tweak this line to execute only when the macro variable 'filter' is 'y' */
	var &amp;amp;_field;
run;&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 May 2023 15:06:21 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2023-05-19T15:06:21Z</dc:date>
    <item>
      <title>Conditionally Execuete Where clause in proc print</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Execuete-Where-clause-in-proc-print/m-p/876682#M346333</link>
      <description>&lt;P&gt;In the following code, I want to execute the where clause in proc print only if the macro variable 'filter' is 'y' otherwise it should not execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let target_table=&amp;amp;datasource;
%global prompt;
%filter ='y';

proc sort data= "&amp;amp;envPath/data/gb/&amp;amp;datasource" out=sorted nodupkey /*or noduprecs if sorting all vars*/;
	by &amp;amp;_field /* or list of vars */;
run; 
proc print data= sorted noobs;
	where &amp;amp;parameter_1 in ("&amp;amp;parameter_2"); /** need help here to tweak this line to execute only when the macro variable 'filter' is 'y' */
	var &amp;amp;_field;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 May 2023 15:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Execuete-Where-clause-in-proc-print/m-p/876682#M346333</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2023-05-19T15:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Execuete Where clause in proc print</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Execuete-Where-clause-in-proc-print/m-p/876684#M346334</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let filter=y;

proc print data= sorted noobs;
	%if &amp;amp;filter=y %then %do; where &amp;amp;parameter_1 in ("&amp;amp;parameter_2"); %end;
	var &amp;amp;_field;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notes: you typed &lt;FONT face="courier new,courier"&gt;%filter='y';&lt;/FONT&gt; which is incorrect. You have to use &lt;FONT face="courier new,courier"&gt;%let&lt;/FONT&gt; as I did, and you should not be enclosing macro variable values in quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes that the rest of the WHERE statement is correct, which I don't know, and you haven't shown that &amp;amp;parameter_1 or &amp;amp;parameter_2 have been assigned values.&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 15:15:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Execuete-Where-clause-in-proc-print/m-p/876684#M346334</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-19T15:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Execuete Where clause in proc print</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Execuete-Where-clause-in-proc-print/m-p/876685#M346335</link>
      <description>&lt;P&gt;Why concerned about "executing" the where clause? Does this mean that you&amp;nbsp; may not always define values for the other macro variables and are looking to avoid other problems because of that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Not executing" a Where clause is somewhat similar conceptually to "the result of the where is always true" (no filtering is done).&lt;/P&gt;
&lt;P&gt;It may be more robust to write such as Where than to invoke the macro processor logic. But no examples of what the other macro variables might look like ...&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 15:28:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Execuete-Where-clause-in-proc-print/m-p/876685#M346335</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-19T15:28:16Z</dc:date>
    </item>
  </channel>
</rss>

