<?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 sas macro parameter to represent condition of rows screen in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-parameter-to-represent-condition-of-rows-screen/m-p/483371#M125339</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I want to ask a general question.&lt;/P&gt;&lt;P&gt;Many times I am asked to create a summary report for different populations.&lt;/P&gt;&lt;P&gt;In order to do it efficiency I am using macro.&lt;/P&gt;&lt;P&gt;In the Macro I define a parameter that define the population.&lt;/P&gt;&lt;P&gt;The problem is that sometimes I need that there will not be any rows&amp;nbsp;screen.&lt;/P&gt;&lt;P&gt;The code here just show you what i want but the way it is written is wrong&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl;
input ID X $ Z;
cards;
1  a 2 
2  a 2
3  a 1
4  b 1
5  b 2
6  c 2
7  c 1
8  c 1
9  c 2
10 c 2
;
run;

%macro mmacro(condition);
PROC SQL;
	create table xxx as
	select 	   
	from tbl
	where &amp;amp;condition.
;
QUIT;
%mend;

/*Run1*/
%mmacro(condition=(x='a' and z='1');
/*Run2*/
%mmacro(condition=(x='a' and z='2');
/*Run3*/
%mmacro(condition=((x='b' OR x='c') and z='2');
/*Run4*/
%mmacro(condition=((x='b' OR x='c'));
/*Run5*/
%mmacro(condition=((x='b' OR x='c'));
/*Run6*/
%mmacro(condition=((no condition));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Aug 2018 13:07:53 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2018-08-02T13:07:53Z</dc:date>
    <item>
      <title>sas macro parameter to represent condition of rows screen</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-parameter-to-represent-condition-of-rows-screen/m-p/483371#M125339</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I want to ask a general question.&lt;/P&gt;&lt;P&gt;Many times I am asked to create a summary report for different populations.&lt;/P&gt;&lt;P&gt;In order to do it efficiency I am using macro.&lt;/P&gt;&lt;P&gt;In the Macro I define a parameter that define the population.&lt;/P&gt;&lt;P&gt;The problem is that sometimes I need that there will not be any rows&amp;nbsp;screen.&lt;/P&gt;&lt;P&gt;The code here just show you what i want but the way it is written is wrong&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl;
input ID X $ Z;
cards;
1  a 2 
2  a 2
3  a 1
4  b 1
5  b 2
6  c 2
7  c 1
8  c 1
9  c 2
10 c 2
;
run;

%macro mmacro(condition);
PROC SQL;
	create table xxx as
	select 	   
	from tbl
	where &amp;amp;condition.
;
QUIT;
%mend;

/*Run1*/
%mmacro(condition=(x='a' and z='1');
/*Run2*/
%mmacro(condition=(x='a' and z='2');
/*Run3*/
%mmacro(condition=((x='b' OR x='c') and z='2');
/*Run4*/
%mmacro(condition=((x='b' OR x='c'));
/*Run5*/
%mmacro(condition=((x='b' OR x='c'));
/*Run6*/
%mmacro(condition=((no condition));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 13:07:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-parameter-to-represent-condition-of-rows-screen/m-p/483371#M125339</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-08-02T13:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro parameter to represent condition of rows screen</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-parameter-to-represent-condition-of-rows-screen/m-p/483374#M125341</link>
      <description>&lt;P&gt;Since you are already working within a macro, the change should be straightforward.&amp;nbsp; You already have this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where condition=&amp;amp;condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change it to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if %length(&amp;amp;condition) %then where condition=&amp;amp;condition.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You still need the semicolon as the next line to end the SELECT statement.&amp;nbsp; On this replacement line, the semicolon ends the %IF %THEN statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 13:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-parameter-to-represent-condition-of-rows-screen/m-p/483374#M125341</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-02T13:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro parameter to represent condition of rows screen</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-parameter-to-represent-condition-of-rows-screen/m-p/483382#M125343</link>
      <description>&lt;P&gt;I would suggest your thinking about it in "not the SAS way".&amp;nbsp; Step 1 assign groups, Step 2 freq or means or whichever, by groups.&amp;nbsp; E.g.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token procnames"&gt;Data&lt;/SPAN&gt; tbl&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt; input&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;ID&lt;/SPAN&gt; X &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; Z&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt; if x="a" and z=1 then group=1;&lt;BR /&gt; if...; &lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt; 1 a 2 2 a 2 3 a 1 4 b 1 5 b 2 6 c 2 7 c 1 8 c 1 9 c 2 10 c 2 &lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;For example, a simple illustration based on inbuilt table:&lt;/P&gt;
&lt;PRE&gt;data class;
  set sashelp.class;
  if age &amp;lt;12 then do;
    agegrp="Up to 12";
    output;
  end;
  else if 12 &amp;lt;= age &amp;lt; 14 then do;
    agegrp="Up to 14";
    output;
  end;
  else do;
    agegrp="All";
    output;
  end;
run;
proc freq data=class noprint;
  tables agegrp*sex / out=want;
run;&lt;/PRE&gt;
&lt;P&gt;This is far more resource efficient, easier to code, and more robust.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do note there are a fair few logical errors in your code also.&amp;nbsp; The create table will overwrite each time.&amp;nbsp; Variable Z is a numeric variable, you are logically trying to match to a text string with:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;and z&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'1'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;Not a good idea.&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>Thu, 02 Aug 2018 13:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-parameter-to-represent-condition-of-rows-screen/m-p/483382#M125343</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-02T13:36:33Z</dc:date>
    </item>
  </channel>
</rss>

