<?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: Simply macro in in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557557#M155444</link>
    <description>&lt;P&gt;Perhaps something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro error_check(whereclause=);

	%let X=1;
	
	proc sql;
	create table lab&amp;amp;X as
 	select State,ID,age,GEM1,GEM1_CNT
 	from have  
 	where &amp;amp;whereclause
	order by State,ID;

%mend;

%error_check(whereclause=%nrstr((State in(1,2,8) and GEM1 not 
    in(0,2)) or (State in(3,5,6) and GEM1 not in(0,8)) or 
	(State in(1,2,8) and GEM1=1 and GEM1_CNT is null)))&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 09 May 2019 18:32:43 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-05-09T18:32:43Z</dc:date>
    <item>
      <title>Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557514#M155427</link>
      <description>&lt;P&gt;Hello experts:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macro program shown below.&amp;nbsp; &amp;nbsp;As you could see every macro is very similar, the difference is in the combination of different numbers.&amp;nbsp; &amp;nbsp;I have about 20 macros (%create_lab) and too long to list here.&amp;nbsp; &amp;nbsp;I am wondering if there is a way to simplify the LONG code.&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro error_check;

	%let X=1;
	
	proc sql;
	create table lab&amp;amp;X as
 	select State,ID,age,GEM1,GEM1_CNT
 	from have  
 	where (State in(1,2,8) and GEM1 not in(0,2)) or
	(State in(3,5,6) and GEM1 not in(0,8)) or 
	(State in(1,2,8) and GEM1=1 and GEM1_CNT is null)
	order by State,ID;

%macro create_lab;
	proc print data=lab&amp;amp;X noobs label;
		by State;
		title2 "Check &amp;amp;X:&amp;amp;&amp;amp;&amp;amp;lab_&amp;amp;X";
	run;
%mend create_lab;
%create_lab;

		%let i=(&amp;amp;X + 1 );
		%let X=%eval(&amp;amp;i);

		proc sql; 
			create table lab&amp;amp;X as
		 	select State,ID,age,GEM2,GEM2_CNT
		 	from have
		 	where (State in(3,4,6,8) and GEM2 not in(0,1,2)) or
				(State in(1,2,5) and GEM2 not in(8)) or
			    (State in(4,8) and GEM2=1 and GEM2_CNT is null)
		 	order by State,ID;
		%create_lab;


		%let i=(&amp;amp;X + 1 );
		%let X=%eval(&amp;amp;i);

		proc sql;
			create table lab&amp;amp;X as
		 	select State,ID,age,GEM3,GEM3_CNT
		 	from have 
		 	where (State in(3,4,6) and GEM3 not in(8)) or
			(State in(2,5,8) and GEM3 not in (0,1,2)) or
			(State in(1,2,5) and GEM3=1 and GEM3_CNT is null) 

		 	order by State,ID;
		%create_lab;

		%let i=(&amp;amp;X + 1 );
		%let X=%eval(&amp;amp;i);

		proc sql;
			create table lab&amp;amp;X as
		 	select State,ID,age,GEM4,GEM4_CNT
		 	from have 
		 	where (State in(3,4,9) and GEM4 not in(6,8)) or
			(State in(0,5,9) and GEM4 not in (6,9)) or
			(State in(6,8) and GEM4=1 and GEM4_CNT is null) 

		 	order by State,ID;
		%create_lab;


		%let i=(&amp;amp;X + 1 );
		%let X=%eval(&amp;amp;i);
		.
		.
		.
		%create_lab;


		%let i=(&amp;amp;X + 1 );
		%let X=%eval(&amp;amp;i);
		.
		.
		.
		%create_lab;

%mend error_check;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 May 2019 16:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557514#M155427</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-05-09T16:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557518#M155429</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello experts:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macro program shown below.&amp;nbsp; &amp;nbsp;As you could see every macro is very similar, the difference is in the combination of different numbers.&amp;nbsp; &amp;nbsp;I have about 20 macros (%create_lab) and too long to list here.&amp;nbsp; &amp;nbsp;I am wondering if there is a way to simplify the LONG code.&amp;nbsp; Thanks.&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I guess I would like you to be more specific. "Combination of different numbers"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that this part of the macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where (State in(3,4,6,8) and GEM2 not in(0,1,2)) or
				(State in(1,2,5) and GEM2 not in(8)) or
			    (State in(4,8) and GEM2=1 and GEM2_CNT is null)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If so, you could have arguments to macro which allow the macro to run on any valid combination of numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro error_check(state=, gem2=);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro error_check(where_clause=);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Finally, please go back to the first post in this thread and provide a meaningful title. Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 17:04:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557518#M155429</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-09T17:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557526#M155432</link>
      <description>&lt;P&gt;I have a big macro (error_check) and a small macro (create_lab).&amp;nbsp; &amp;nbsp;And my goal is creating another macro before the "%let i=(&amp;amp;X + 1 );&lt;BR /&gt;%let X=%eval(&amp;amp;i);" to avoid repeat codes shown below.&amp;nbsp; &amp;nbsp;I hope I could only have one code could cover all 20 repeating Proc SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;% macro repeat(...);

%let i=(&amp;amp;X + 1 );
%let X=%eval(&amp;amp;i);

proc sql;
.
.
%create_lab;

%mend repeat (...);
%repeart (gem1...);
%repeat (gem2...);
%repeat (gem3...);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 May 2019 17:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557526#M155432</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-05-09T17:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557534#M155436</link>
      <description>&lt;P&gt;Well, it's still not clear to me exactly what you are looking for.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I specifically asked, and did not receive an answer, to this question:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess I would like you to be more specific. "Combination of different numbers"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that this part of the macro?&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;where&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;State &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;4&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;6&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;8&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; and GEM2 &lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&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 number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; or
				&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;State &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;5&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; and GEM2 &lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;8&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; or
			    &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;State &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;4&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;8&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; and GEM2&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; and GEM2_CNT is null&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 09 May 2019 17:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557534#M155436</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-09T17:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557537#M155437</link>
      <description>&lt;P&gt;Yes&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 17:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557537#M155437</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-05-09T17:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557539#M155438</link>
      <description>&lt;P&gt;I think if this were my data and I was concerned about (fixed known)&amp;nbsp;combinations of values that I might be strongly tempted to create a temporary variable or two by concatenating the two variables with a delimiter character. Then make a format using that know&amp;nbsp;list to allow detecting valid (or invalid) combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This approach may be even stronger if your values of Gem1, Gem2, etc take the same range of valid and invalid combinations. Something along the line of&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value $stgem1_ 
'1_1', '1_2', '2_2'= 'Valid'
other = 'Invalid'
;
value $stgem2_ 
'2_1', '3_2', '2_2'= 'Valid'
other = 'Invalid'
;
run;

data example;
   do st= 1 to 3;
   do gem1= 0 to 2;
   do gem2= 0 to 2;
      statusgem1= put( catx('_', st, gem1), stgem1_.);
      statusgem2= put( catx('_', st, gem2), stgem2_.);
      output;
   end;
   end;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That moves the logic of combination out of possibly awkward to maintain if/then/else statements and can greatly simplify or remove the need for macro code at all.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 17:42:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557539#M155438</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-09T17:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557557#M155444</link>
      <description>&lt;P&gt;Perhaps something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro error_check(whereclause=);

	%let X=1;
	
	proc sql;
	create table lab&amp;amp;X as
 	select State,ID,age,GEM1,GEM1_CNT
 	from have  
 	where &amp;amp;whereclause
	order by State,ID;

%mend;

%error_check(whereclause=%nrstr((State in(1,2,8) and GEM1 not 
    in(0,2)) or (State in(3,5,6) and GEM1 not in(0,8)) or 
	(State in(1,2,8) and GEM1=1 and GEM1_CNT is null)))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 May 2019 18:32:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557557#M155444</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-09T18:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557559#M155446</link>
      <description>&lt;P&gt;If use&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;whereclause&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I still need to generate 20 codes cause I have 20 GEMs.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 18:45:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557559#M155446</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-05-09T18:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557561#M155448</link>
      <description>&lt;P&gt;Gem1 to Gem20 is just the sample name I gave in this test.&amp;nbsp; &amp;nbsp;The actual GEM names are various not discipline.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 18:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557561#M155448</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-05-09T18:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557569#M155452</link>
      <description>&lt;P&gt;Is it possible I could generate 5 groups of numbers? Something is like below.&amp;nbsp; &amp;nbsp;However, I don't know if I could add () into a new macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro repeat (Gem, number1, number2, number3, number4, number5);
		%let i=(&amp;amp;X + 1 );
		%let X=%eval(&amp;amp;i);

		proc sql; 
			create table lab&amp;amp;X as
		 	select State,ID,age,&amp;amp;GEM,&amp;amp;GEM_CNT
		 	from have
		 	where (State in &amp;amp;number1 and &amp;amp;GEM not in &amp;amp;number2 ) or
				(State in &amp;amp;number3 and &amp;amp;GEM not in &amp;amp;number4) or
			    (State in &amp;amp;number5 and &amp;amp;GEM=1 and &amp;amp;GEM_CNT is null)
		 	order by State,ID;
		%create_lab;
%mend repeat;
%repeat ( gem1, (3,4,6,8), (0,1,2), (1,2,5), (8), (4,8) );
%repeat ( gem2, (3,4,6,8), (0,1,2), (1,2,5), (8), (4,8) );
%repeat ( gem3, (3,4,6), (8), (2,5,8), (0,1,2), (1,2,5));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 19:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557569#M155452</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-05-09T19:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557571#M155453</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;If use&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;whereclause&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I still need to generate 20 codes cause I have 20 GEMs.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Again I'm confused. I thought the problem was to reduce the many macros into a single macro, which I have provided a possible solution. Then you call the macro as many times as necessary.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 19:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557571#M155453</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-09T19:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557622#M155467</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Gem1 to Gem20 is just the sample name I gave in this test.&amp;nbsp; &amp;nbsp;The actual GEM names are various not discipline.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;????&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 21:37:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557622#M155467</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-09T21:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557625#M155468</link>
      <description>&lt;P&gt;Data&lt;/P&gt;
&lt;P&gt;Rules&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know what your starting data looks like.&lt;/P&gt;
&lt;P&gt;From your code I am not willing to try to spend time backtracking as to what a general rule for any of this might be&lt;/P&gt;
&lt;P&gt;And don't even know what the desired result is supposed to look like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If at all possible do not include special characters in macro parameters such as () or comma. The IN operator does not require a comma separator (since SAS 9.0 or so). So do not include them in parameters.&lt;/P&gt;
&lt;P&gt;Since you know that your are going to use the values in an IN comparison then leave the () with the IN code to make things clearer about what is passed into the macro&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro repeat (Gem, number1, number2, number3, number4, number5);
		%let i=(&amp;amp;X + 1 );
		%let X=%eval(&amp;amp;i);

		proc sql; 
			create table lab&amp;amp;X as
		 	select State,ID,age,&amp;amp;GEM,&amp;amp;GEM_CNT
		 	from have
		 	where (State in (&amp;amp;number1) and &amp;amp;GEM not in (&amp;amp;number2) ) or
				(State in (&amp;amp;number3) and &amp;amp;GEM not in (&amp;amp;number4) ) or
			    (State in (&amp;amp;number5) and &amp;amp;GEM=1 and &amp;amp;GEM_CNT is null)
		 	order by State,ID;&lt;BR /&gt;                %quit; /* unless you know that creat_lab is supposed to be part of the &lt;BR /&gt;                        same Proc sql call*/
		%create_lab;
%mend repeat;
%repeat(  gem1 ,  3 4 6 8  ,  0 1 2  ,  1 2 5 ,   8  ,  4 8   );
%repeat(  gem2 ,  3 4 6 8 ,   0 1 2 ,   1 2 5 ,   8  ,  4 8   );
%repeat(  gem3 ,  3 4 6  ,  8  ,  2 5 8 ,   0 1 2 ,   1 2 5  );&lt;/PRE&gt;
&lt;P&gt;I would be very careful about use of macro variables such as your X above that are not explicitly passed into the macro.&lt;/P&gt;
&lt;P&gt;Also be very wary of not explicitly ending Procs or data step calls as sometimes depending on your macro language you may have an unexpected boundary (or not boundary in some cases) when calling other macros.&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, 09 May 2019 21:52:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557625#M155468</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-09T21:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: Simply macro in</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557668#M155496</link>
      <description>&lt;P&gt;A large part of your problem with this thread is you haven't asked a clear question, or clear answers to other folks' questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any case, assuming I've properly guessed what you're trying to do, this is how I'd approach it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data metadata;
   length id 8 where $1000;
   infile datalines;
   input;
   id+1;
   where=_infile_;
   datalines4;
(State in (1,2,8)   and GEM1 not in (0,2))   or (State in (3,5,6) and GEM1 not in (0,8))   or (State in (1,2,8) and GEM1=1 and GEM1_CNT is null)
(State in (3,4,6,8) and GEM2 not in (0,1,2)) or (State in (1,2,5) and GEM2 not in (8))     or (State in (4,8)   and GEM2=1 and GEM2_CNT is null)
(State in (3,4,6)   and GEM3 not in (8))     or (State in (2,5,8) and GEM3 not in (0,1,2)) or (State in (1,2,5) and GEM3=1 and GEM3_CNT is null)
(State in (3,4,9)   and GEM4 not in (6,8))   or (State in (0,5,9) and GEM4 not in (6,9))   or (State in (6,8)   and GEM4=1 and GEM4_CNT is null)
;;;;
run;

%macro code;
   %let id=%trim(id);
   %let where=%trim(&amp;amp;where);

   proc sql;
      create table lab&amp;amp;id as
      select State,ID,age,GEM1,GEM1_CNT
      from have
      where &amp;amp;where
      order by State,ID;
    quit;

    proc print data=lab&amp;amp;id noobs label;
      by State;
      title2 "Check &amp;amp;id:lab&amp;amp;id";
    run;
%mend;
%loop_control(control=metadata)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Download these macros:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas" target="_blank" rel="noopener"&gt;https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/parmv.sas" target="_blank" rel="noopener"&gt;https://github.com/scottbass/SAS/blob/master/Macro/parmv.sas&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 01:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simply-macro-in/m-p/557668#M155496</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-10T01:58:47Z</dc:date>
    </item>
  </channel>
</rss>

