<?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: use &amp;gt; symbol in where condition within macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484148#M125656</link>
    <description>&lt;P&gt;Thank you very much,&lt;/P&gt;&lt;P&gt;It is exactly what I wanted.&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>Sun, 05 Aug 2018 12:35:16 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2018-08-05T12:35:16Z</dc:date>
    <item>
      <title>use &gt; symbol in where condition within macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484121#M125637</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;Why this code is not working?&lt;/P&gt;&lt;P&gt;I want to use condition of all branches &amp;gt;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl;
input ID  branch;
cards;
1 100
2 100
3 200
4 300
5 400
6 500
7 500
8 500
9 500
10 500
;
run;

%macro rjoe(x,branchP);
PROC SQL;
	create table outcome_&amp;amp;x. as
	select *	   
	from tbl
	where branch in (&amp;amp;branchP.)
;
QUIT;
%mend;

%rjoe(x=1,branchP=100);
%rjoe(x=2,branchP=200);
%rjoe(x=3,branchP=300);
%rjoe(x=4,branchP=400);
%rjoe(x=5,branchP=500);
%rjoe(x=6,branchP=100 200 300 400 500); 
%rjoe(x=5,branchP=&amp;gt;0);/*It is  not working .why??*/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Aug 2018 08:59:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484121#M125637</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-08-05T08:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: use &gt; symbol in where condition within macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484123#M125639</link>
      <description>&lt;P&gt;Because you end up with this invalid code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	create table outcome_6 as
	select *	   
	from tbl
	where branch in (&amp;gt;0)
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Aug 2018 09:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484123#M125639</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-05T09:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: use &gt; symbol in where condition within macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484127#M125643</link>
      <description>&lt;P&gt;But in your answer you didn't use macro.&lt;/P&gt;&lt;P&gt;My question was how to use the condition &amp;gt;0 &amp;nbsp;under macro (with a macro varaible)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 10:31:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484127#M125643</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-08-05T10:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: use &gt; symbol in where condition within macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484131#M125646</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%rjoe&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;x&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;5&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;branchP&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Because in where condition you are using in operator and while calling macro you are giving value '&amp;gt;0' which is invalid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;when Macro get resolves&amp;nbsp; the where condition look like this&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; branch &lt;SPAN class="token operator"&gt;in (&amp;gt;0) &lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;which is invalid&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can modify the code like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;%macro rjoe(x,branchP);&lt;BR /&gt;PROC SQL;&lt;BR /&gt; create table outcome_&amp;amp;x. as&lt;BR /&gt; select * &lt;BR /&gt; from tbl&lt;BR /&gt; where branch &amp;amp;branchP.&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;%rjoe(x=1,branchP=in (100);&lt;BR /&gt;%rjoe(x=2,branchP=in (200));&lt;BR /&gt;%rjoe(x=3,branchP=in (300));&lt;BR /&gt;%rjoe(x=4,branchP=in (400));&lt;BR /&gt;%rjoe(x=5,branchP=in (500));&lt;BR /&gt;%rjoe(x=6,branchP=in (100 200 300 400 500)); &lt;BR /&gt;%rjoe(x=5,branchP=&amp;gt;0));&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Aug 2018 11:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484131#M125646</guid>
      <dc:creator>akash1088</dc:creator>
      <dc:date>2018-08-05T11:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: use &gt; symbol in where condition within macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484137#M125649</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;But in your answer you didn't use macro.&lt;/P&gt;
&lt;P&gt;My question was how to use the condition &amp;gt;0 &amp;nbsp;under macro (with a macro varaible)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I resolved the macro manually to show you the resulting code, and why it can't work. This is not a macro problem, but a case of forcing the macro to create crappy code. Since you can't use &amp;gt;0 in the in-list in base SAS, you also can't do it via the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once again, for the umpteenth time:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Get working base SAS code before you make it dynamic with a macro!&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 11:30:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484137#M125649</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-05T11:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: use &gt; symbol in where condition within macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484139#M125651</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;But in your answer you didn't use macro.&lt;/P&gt;
&lt;P&gt;My question was how to use the condition &amp;gt;0 &amp;nbsp;under macro (with a macro varaible)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Agreeing with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, write working SAS code first. Then you can much more easily turn it into a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I gave a solution in your &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/keyword-parameters/m-p/484129#M125644" target="_self"&gt;other thread&lt;/A&gt;. Does it make sense? (And please don't post the same question twice)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MODERATOR: can you combine these threads into one?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 11:42:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484139#M125651</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-05T11:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: use &gt; symbol in where condition within macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484146#M125655</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;:&amp;nbsp;In practice it's more common to pass the &lt;EM&gt;entire&lt;/EM&gt; WHERE condition to the macro:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where &amp;amp;branchP&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(in this case you'd better use a more generic name like &lt;FONT face="courier new,courier"&gt;cond&lt;/FONT&gt; for this parameter since it is no longer limited to conditions on variable &lt;FONT face="courier new,courier"&gt;branch&lt;/FONT&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This requires more typing in the macro calls than previously, e.g.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%rjoe(7, branch in (200,500))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the benefit is that you now have unlimited flexibility regarding the WHERE condition. Examples:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%rjoe(8, 200&amp;lt;=branch&amp;lt;=400)
%rjoe(9, branch in (select 25*age from sashelp.class))
%rjoe(10, .&amp;lt;branch&amp;lt;300 or id=8)
%rjoe(11, (id=8 or .&amp;lt;branch&amp;lt;300))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The latter example shows that sometimes additional parentheses (or macro quoting functions) are necessary to avoid misinterpretations on the part of the macro processor (here: &lt;FONT face="courier new,courier"&gt;id=&lt;/FONT&gt;... would look as if there was a keyword parameter &lt;FONT face="courier new,courier"&gt;id&lt;/FONT&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Addendum: With this technique it's also very easy to code an "empty" condition (which amounts to a PROC SQL step &lt;EM&gt;without&lt;/EM&gt; a WHERE clause):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%rjoe(12, 1)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Aug 2018 13:11:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484146#M125655</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-08-05T13:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: use &gt; symbol in where condition within macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484148#M125656</link>
      <description>&lt;P&gt;Thank you very much,&lt;/P&gt;&lt;P&gt;It is exactly what I wanted.&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>Sun, 05 Aug 2018 12:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-gt-symbol-in-where-condition-within-macro/m-p/484148#M125656</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-08-05T12:35:16Z</dc:date>
    </item>
  </channel>
</rss>

