<?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: Thoughts and questions: why this kind of macro is so difficult to debug. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965743#M375962</link>
    <description>&lt;P&gt;Related to the original question, there is also the %INM macro which may be of use, and is a lot less typing than creating your own macro to find matches in a text string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro inm(slist,s);
    /* SAS Macro %inm to see if &amp;amp;s is contained in a string or list &amp;amp;slist                 */
    /* Borrowed from https://groups.google.com/forum/#!topic/comp.soft-sys.sas/fWcSDgg11tE */
    %if %sysfunc(indexw(&amp;amp;slist,&amp;amp;s)) gt 0 %then 1 ;
    %else 0;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output of the macro is a&amp;nbsp;1 indicating a match, or a zero indicates no match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example of use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let countrylist=AU AT CH;
%let thiscountry=AT;
%if %inm(&amp;amp;countrylist,&amp;amp;thiscountry) %then %do;
    %put This country is &amp;amp;thiscountry, Match found;
%end;
%let thiscountry=RP;
%if not %inm(&amp;amp;countrylist,&amp;amp;thiscountry) %then %do;
    %put This country is &amp;amp;thiscountry, Match not found;
%end;&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;Sometimes (most times?) asking here in the forum if there is a macro to perform your task is a good first step, rather than just going ahead and trying to write the macro yourself.&lt;/P&gt;</description>
    <pubDate>Mon, 05 May 2025 12:00:40 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2025-05-05T12:00:40Z</dc:date>
    <item>
      <title>Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965527#M375871</link>
      <description>&lt;P&gt;The correct code is as follows. But I used almost an hour to figure it out and still have questions about it. (ps: I made these mistakes while doing the practice questions on page 285 in Macro1: essentials course notes pdf, that was a complex question.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) The correct code and results&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ctrylist(ctry1)/minoperator;
%let list1=AT AU CA CH;
%put &amp;amp;list1;
%if &amp;amp;ctry1 in &amp;amp;list1 %then %do;
   %put &amp;amp;ctry1;
%end;
%else %do;
   %put ERROR: &amp;amp;ctry1 is an invalid country code.;
   %put ERROR: Valid country codes include &amp;amp;list1.;
%end;
%mend ctrylist;
%ctrylist(AU);
%ctrylist(zz);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1746110752502.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106643i309746889516A129/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1746110752502.png" alt="dxiao2017_0-1746110752502.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) How I used almost an hour to make mistakes and correct it. At first I wrote something like this (I did not know what's wrong with my mind then and forgot to write the &lt;EM&gt;semicolon ;&lt;/EM&gt; behind the two &lt;EM&gt;%put&lt;/EM&gt; statements in the &lt;EM&gt;%else %do&lt;/EM&gt; statement, also when debugging I kept ignore this obvious mistake and costed me a lot of time to figure out the problem):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ctrylist(ctry1);
%let list1=AT AU CA CH;
%put &amp;amp;list1;
%if &amp;amp;ctry1 in &amp;amp;list1 %then %do;
   %put &amp;amp;ctry1;
%end;
%else %do;
   %put ERROR: &amp;amp;ctry1 is an invalid country code.
   %put ERROR: Valid country codes include &amp;amp;list1.
%end;
%mend ctrylist;
%ctrylist(AU);
%ctrylist(zz);      &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And I got error message like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_1-1746111545239.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106644iCB8D974C776CEB74/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_1-1746111545239.png" alt="dxiao2017_1-1746111545239.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I am not good at using error message to help debug, also did not pay attention to where did the error occur. The possible mistakes came into my mind were: 1) maybe the &lt;EM&gt;%if &amp;amp;ctry1 in &amp;amp;list1&lt;/EM&gt;&amp;nbsp; statement has problem, maybe I should try a &lt;EM&gt;&amp;amp;list&lt;/EM&gt; with commas that separate the values, and 2) maybe the first &lt;EM&gt;%put&lt;/EM&gt; in the first &lt;EM&gt;%if %then&lt;/EM&gt; statement is not necessary. Then I tried something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ctrylist2(ctry2);
%let list2='AT','AU','CA','CH';
%if &amp;amp;ctry2 in (&amp;amp;list2) %then %do;
   &amp;amp;ctry2;
%end;
%else %do;
   %put ERROR: &amp;amp;ctry2 is an invalid country code.
   %put ERROR: Valid country codes include &amp;amp;list2.
%end;
%mend ctrylist2;
%ctrylist(AU);
%ctrylist(zz);       &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And I got the same error message:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_2-1746112200230.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106645iC65172E6FED0ED3D/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_2-1746112200230.png" alt="dxiao2017_2-1746112200230.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Then I did not know what to do. The only thing came into my mind was, maybe an option &lt;EM&gt;minoperator&lt;/EM&gt; should be added (because in that section in the material there was content of &lt;EM&gt;minoperator&lt;/EM&gt;), then I tried something like this:&lt;/P&gt;
&lt;PRE&gt;%macro ctrylist2(ctry2)/minoperator;&lt;BR /&gt;%let list2='AT','AU','CA','CH';&lt;BR /&gt;%if &amp;amp;ctry2 in (&amp;amp;list2) %then %do;&lt;BR /&gt;   %put &amp;amp;ctry2;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;   %put ERROR: &amp;amp;ctry2 is an invalid country code.&lt;BR /&gt;   %put ERROR: Valid country codes include &amp;amp;list2.&lt;BR /&gt;%end;&lt;BR /&gt;%mend ctrylist2;&lt;BR /&gt;%ctrylist(AU);&lt;BR /&gt;%ctrylist(zz);      &lt;/PRE&gt;
&lt;P&gt;And I got the exact same error message. I did not know why I kept ignore the obvious mistake that there was no &lt;EM&gt;semicolon ;&lt;/EM&gt; after the two &lt;EM&gt;%put&lt;/EM&gt; statements, I even did not put my eyesight at the two statements, like I kept ignore an obvious, major mistake intentionally. Then I think I cannot figure it out and was going to post the problem into this community. But right before I post the problem my attention and eyesight somehow switched to and see the mistake: I did not write &lt;EM&gt;semicolon ;&lt;/EM&gt; after the two statements. And I corrected it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) What I learnt from the experience: a) do not in a hurry and too eager to find out what is wrong, just look into every details of the code, b)look at the error message, especially where does the error message occur,&amp;nbsp; c) when writing complex macros, keep relax and keep attention focused and enjoy, do not rush. d) When writing macro, it is easy for me to forget the semicolon, or sometimes added unnecessary semicolon or put semicolon at wrong place, I made this mistake twice before, the scenario is like(I forget another example which use a &lt;EM&gt;%if %then&lt;/EM&gt; and &lt;EM&gt;where&lt;/EM&gt; statement in a &lt;EM&gt;data step&lt;/EM&gt;, which has the similar usage of the semicolon, could anyone come up with a similar example, many thanks) this, for this incorrect code I should put the &lt;EM&gt;semicolon&lt;/EM&gt; after the&lt;EM&gt; &amp;amp;&amp;amp;b&amp;amp;i&lt;/EM&gt; right before &lt;EM&gt;run;&lt;/EM&gt; statement and after the &lt;EM&gt;%end;&lt;/EM&gt; statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
   set %do i=1 to &amp;amp;sqlobs;
         &amp;amp;&amp;amp;b&amp;amp;i;
       %end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4) I still have questions about the codes:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a) do &lt;EM&gt;%if &amp;amp;ctry1 in &amp;amp;list1&lt;/EM&gt; and &lt;EM&gt;%if &amp;amp;ctry2 in (&amp;amp;list2)&lt;/EM&gt; work the same way? I mean the syntax of the &lt;EM&gt;%if in&lt;/EM&gt; statement, the first one does not need the brackets and the second one does need the brackets, isn't it?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list1=AT AU CA CH;
%put &amp;amp;list1;
%if &amp;amp;ctry1 in &amp;amp;list1 %then %do;
   %put &amp;amp;ctry1;
%end;

%let list2='AT','AU','CA','CH';
%if &amp;amp;ctry2 in (&amp;amp;list2) %then %do;
   %put &amp;amp;ctry2;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;b) what does the &lt;EM&gt;minoperator&lt;/EM&gt; options do? why do I need it after the macro name? Without it I got a similar error message (only without the error message about &lt;EM&gt;%put).&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ctrylist2(ctry2);
%let list2='AT','AU','CA','CH';
%if &amp;amp;ctry2 in (&amp;amp;list2) %then %do;
   %put &amp;amp;ctry2;
%end;
%else %do;
   %put ERROR: &amp;amp;ctry2 is an invalid country code.;
   %put ERROR: Valid country codes include &amp;amp;list2.;
%end;
%mend ctrylist2;
%ctrylist(AU);
%ctrylist(zz);   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_3-1746114292728.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106656i4040E8A71C8B3176/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_3-1746114292728.png" alt="dxiao2017_3-1746114292728.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 May 2025 16:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965527#M375871</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-05-01T16:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965534#M375873</link>
      <description>&lt;P&gt;I forgot to say with this code (if I use &lt;EM&gt;%if &amp;amp;ctry1 in &amp;amp;list1&lt;/EM&gt; statement, with blank as the delimiter in the &lt;EM&gt;&amp;amp;list&lt;/EM&gt;), I got different error message when I do not use &lt;EM&gt;minoperator&lt;/EM&gt; option, does this mean whenever I use such a &lt;EM&gt;&amp;amp;list&lt;/EM&gt; in my macro I have to add the &lt;EM&gt;minoperator&lt;/EM&gt; option?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ctrylist(ctry1);
%let list1=AT AU CA CH;
%put &amp;amp;list1;
%if &amp;amp;ctry1 in &amp;amp;list1 %then %do;
   %put &amp;amp;ctry1;
%end;
%else %do;
   %put ERROR: &amp;amp;ctry1 is an invalid country code.;
   %put ERROR: Valid country codes include &amp;amp;list1.;
%end;
%mend ctrylist;
%ctrylist(AU);
%ctrylist(zz);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1746118370526.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106657iDA06AD4CBECB0F38/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1746118370526.png" alt="dxiao2017_0-1746118370526.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_1-1746118440413.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106658i7403E5FFBB47DEDC/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_1-1746118440413.png" alt="dxiao2017_1-1746118440413.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 May 2025 16:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965534#M375873</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-05-01T16:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965535#M375874</link>
      <description>&lt;P&gt;You need MINOPERATOR in order use IN with the macro language. Otherwise, the macro processor does not know what to do with it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And in this case, you are calling a macro %ctrylist right after storing the macro %ctrylist2, so that will lead to an error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ctrylist2(ctry2);
%let list2='AT','AU','CA','CH';
%if &amp;amp;ctry2 in (&amp;amp;list2) %then %do;
   &amp;amp;ctry2;
%end;
%else %do;
   %put ERROR: &amp;amp;ctry2 is an invalid country code.
   %put ERROR: Valid country codes include &amp;amp;list2.
%end;
%mend ctrylist2;
%ctrylist(AU);
%ctrylist(zz);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Read more about MINOPERATOR here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a003092012.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a003092012.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 May 2025 16:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965535#M375874</guid>
      <dc:creator>svh</dc:creator>
      <dc:date>2025-05-01T16:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965539#M375878</link>
      <description>&lt;P&gt;A minor issue, however&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ctrylist2(ctry2);
%let list2='AT','AU','CA','CH';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it is unnecessary and potentially harmful to the proper operation of the code to put quotes around the country abbreviations. The commas are also unnecessary. I doubt your %ctrylist2 macro will work with the quotes there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S.: Better to include the log as text in the window that appears when you click on the&amp;nbsp; &amp;lt;/&amp;gt; icon&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1715196634946.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96351i414DE7EE2D1B5DE6/image-size/large?v=v2&amp;amp;px=999" role="button" title="PaigeMiller_0-1715196634946.png" alt="PaigeMiller_0-1715196634946.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 May 2025 17:36:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965539#M375878</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-05-01T17:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965558#M375890</link>
      <description>&lt;P&gt;You define a macro ctrylist2, but try to invoke ctrylist (no 2).&lt;/P&gt;</description>
      <pubDate>Thu, 01 May 2025 21:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965558#M375890</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-05-01T21:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965574#M375895</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466238"&gt;@dxiao2017&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The correct code is as follows. But I used almost an hour to figure it out and still have questions about it. (ps: I made these mistakes while doing the practice questions on page 285 in Macro1: essentials course notes pdf, that was a complex question.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would say that stating "correct code" without any description of what the code is supposed to do does not help at all in why "debugging" might be difficult. &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;I would also add that quite often the biggest issue is unfamiliarity with the basic code needed to perform something. We get a fair number of questions on this forum asking to debug macro code only to find that the poster never had basic code working that would accomplish the desired task(s). The macro processor generates code. If you do not know what the code to generate should look like then macros are &lt;STRONG&gt;extremely difficult to program&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And a fair number of things asked about macros can be accomplished with no macro programming at all. Many of the "loop" type questions about macros can be solved with By group processing for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 May 2025 04:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965574#M375895</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-05-02T04:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965600#M375903</link>
      <description>And you can also do a lot of things in open code rather than with macros if you  build a data step with CALL EXECUTE. Though I did not find that routine until AFTER I learned the macro language...</description>
      <pubDate>Fri, 02 May 2025 14:07:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965600#M375903</guid>
      <dc:creator>svh</dc:creator>
      <dc:date>2025-05-02T14:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965606#M375906</link>
      <description>&lt;P&gt;Message was too long for me, but I have a quick answer for the first thing.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466238"&gt;@dxiao2017&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The correct code is as follows. But I used almost an hour to figure it out and still have questions about it. (ps: I made these mistakes while doing the practice questions on page 285 in Macro1: essentials course notes pdf, that was a complex question.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) The correct code and results&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ctrylist(ctry1)/minoperator;
%let list1=AT AU CA CH;
%put &amp;amp;list1;
%if &amp;amp;ctry1 in &amp;amp;list1 %then %do;
   %put &amp;amp;ctry1;
%end;
%else %do;
   %put ERROR: &amp;amp;ctry1 is an invalid country code.;
   %put ERROR: Valid country codes include &amp;amp;list1.;
%end;
%mend ctrylist;
%ctrylist(AU);
%ctrylist(zz);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1746110752502.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106643i309746889516A129/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1746110752502.png" alt="dxiao2017_0-1746110752502.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could use a pre-debugged macro for testing if values are valid, like this one:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/parmv.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/parmv.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then developing your new macro is going to be easier.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ctrylist(ctry1) ;
  %local parmerr;
  %parmv(ctry1,_val=AT AU CA CH)
  %if (&amp;amp;parmerr) %then %do;
      ... code to handle user entry errors ...
  %end;
  %else %do;
     ... code to actually do what you want ...
  %end;
%mend ctrylist;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt; 73         %macro ctrylist(ctry1) ;
 74           %local parmerr;
 75           %parmv(ctry1,_val=AT AU CA CH)
 76           %if (&amp;amp;parmerr) %then %do;
 77               %put ... code to handle user entry errors ... ;
 78           %end;
 79           %else %do;
 80              %put &amp;amp;=ctry1 ;
 81              %put ... code to actually do what you want ...;
 82           %end;
 83         %mend ctrylist;
 84         
 85         %ctrylist(AT)
 CTRY1=AT
 ... code to actually do what you want ...
 86         %ctrylist(ca)
 CTRY1=CA
 ... code to actually do what you want ...
 87         %ctrylist(zz)
  
 ERROR: Macro CTRYLIST user error.
 ERROR: ZZ is not a valid value for the CTRY1 parameter.
 ERROR: Allowable values are: AT AU CA CH.
 ... code to handle user entry errors ...
 88         %ctrylist(or)
  
 ERROR: Macro CTRYLIST user error.
 ERROR: OR is not a valid value for the CTRY1 parameter.
 ERROR: Allowable values are: AT AU CA CH.
 ... code to handle user entry errors ...&lt;/PRE&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 May 2025 15:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965606#M375906</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-05-02T15:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965651#M375919</link>
      <description>&lt;P&gt;Hi Paige thanks a lot for reply! It's not a minor issue for me, it is where I make mistakes, thanks a lot for telling me this! The code in my previous thread was a little messed up because while debugging, I messed up the three macros %ctrylist, %ctrylist1, %ctrylist2 when test them. Today I tried both (with commas and quotes and without), the code and results are as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ctrylist2(ctry2)/minoperator;
%let list2='AT','AU','CA','CH';
%if &amp;amp;ctry2 in (&amp;amp;list2) %then %do;
   %put &amp;amp;ctry2;
%end;
%else %do;
   %put ERROR: &amp;amp;ctry2 is an invalid country code.;
   %put ERROR: Valid country codes include &amp;amp;list2.;
%end;
%mend ctrylist2;
%ctrylist2(AU);
%ctrylist2(zz); 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;69         %macro ctrylist2(ctry2)/minoperator;
 70         %let list2='AT','AU','CA','CH';
 71         %if &amp;amp;ctry2 in (&amp;amp;list2) %then %do;
 72            %put &amp;amp;ctry2;
 73         %end;
 74         %else %do;
 75            %put ERROR: &amp;amp;ctry2 is an invalid country code.;
 76            %put ERROR: Valid country codes include &amp;amp;list2.;
 77         %end;
 78         %mend ctrylist2;
 79         %ctrylist2(AU);
 ERROR: AU is an invalid country code.
 ERROR: Valid country codes include 'AT','AU','CA','CH'
 80         %ctrylist2(zz);
 ERROR: zz is an invalid country code.
 ERROR: Valid country codes include 'AT','AU','CA','CH'&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ctrylist1(ctry1)/minoperator;
%let list1=AT AU CA CH;
%put &amp;amp;list1;
%if &amp;amp;ctry1 in &amp;amp;list1 %then %do;
   %put &amp;amp;ctry1;
%end;
%else %do;
   %put ERROR: &amp;amp;ctry1 is an invalid country code.;
   %put ERROR: Valid country codes include &amp;amp;list1..;
%end;
%mend ctrylist1;
%ctrylist1(AU);
%ctrylist1(zz);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt; 69         %macro ctrylist1(ctry1)/minoperator;
 70         %let list1=AT AU CA CH;
 71         %put &amp;amp;list1;
 72         %if &amp;amp;ctry1 in &amp;amp;list1 %then %do;
 73            %put &amp;amp;ctry1;
 74         %end;
 75         %else %do;
 76            %put ERROR: &amp;amp;ctry1 is an invalid country code.;
 77            %put ERROR: Valid country codes include &amp;amp;list1..;
 78         %end;
 79         %mend ctrylist1;
 80         %ctrylist1(AU);
 AT AU CA CH
 AU
 81         %ctrylist1(zz);
 AT AU CA CH
 ERROR: zz is an invalid country code.
 ERROR: Valid country codes include AT AU CA CH.&lt;/PRE&gt;
&lt;P&gt;You are right about that the one with commas and quotes actually did not work. So this answers my question of the correct syntax of creating a &lt;EM&gt;&amp;amp;list&lt;/EM&gt; to be used in a macro in a &lt;EM&gt;%if %then&lt;/EM&gt; statement, that is, do not include any commas and quotes in the &lt;EM&gt;&amp;amp;list&lt;/EM&gt; (i.e, use blank as delimiter among the values), and when resolve it in a &lt;EM&gt;%if %then&lt;/EM&gt; statement, write it this way (do not need brackets here): &lt;EM&gt;%if &amp;amp;name in &amp;amp;list %then %do;&lt;/EM&gt;.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;, am I right about this? Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 03 May 2025 13:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965651#M375919</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-05-03T13:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965652#M375920</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181543"&gt;@svh&lt;/a&gt;&amp;nbsp;thanks a lot for reply! Through the link you provide I have downloaded the material about macro for further learning. However, for the explanations about &lt;EM&gt;minoperator&lt;/EM&gt;, I still do not understand. In the materials I can find so far, the descriptions are similar:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) descriptions in SAS 9.4 guide (built in documentation): "&lt;EM&gt;specifies that the macro processor recognizes and evaluates the mnemonic IN and the special character # as logical operators when evaluating arithmetic or logical expressions during the execution of the macro&lt;/EM&gt;".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) descriptions in SAS Macro1: essentials course notes: "&lt;EM&gt;A null value cannot be provided in the list of values after the macro IN operator. Null values must be processed first with a separate %if condition. to enable the macro IN operator, add the MINOPERATOR options&lt;/EM&gt;".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) descriptions in SAS(R) 9.2 Macro Language Reference (the material on the link you provide): "&lt;EM&gt;causes the macro processor to recognize the evaluate both the mnemonic operator In or the special character # as a logical operator in expressions&lt;/EM&gt;".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far my understanding is like this: whenever I use a macro &lt;EM&gt;&amp;amp;list&lt;/EM&gt; or do some arithmetic calculation inside a macro, if my macro does not run through and other syntax is correct, I need to add this &lt;EM&gt;minoperator&lt;/EM&gt; to see if it solves problem.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181543"&gt;@svh&lt;/a&gt;&amp;nbsp;am I right about this, thanks a lot!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you are right about I was "calling a macro %ctrylist right after storing the macro %ctrylist2", I messed up the two macros myself while debugging and test them&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 03 May 2025 13:47:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965652#M375920</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-05-03T13:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965653#M375921</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;thanks a lot for reply! You are right&lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;, I made several mistakes(also without knowing what were the mistakes) when writing macro &lt;EM&gt;ctrylist&lt;/EM&gt;, and then I wrote &lt;EM&gt;ctrylist1&lt;/EM&gt; and &lt;EM&gt;ctrylist2&lt;/EM&gt; to help debug and find out what's wrong, and then I messed up the three macros when test them&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 03 May 2025 13:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965653#M375921</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-05-03T13:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965654#M375922</link>
      <description>&lt;P&gt;First point. MINOPERATOR and MINDELIMITER are the system options to control WHETHER you can use IN as an operator in macro code and if you do WHAT character is used to delimit the items in the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When writing a macro you would normally want to use the MINOPERATOR and MINDELIMITER options of the %MACRO statement to enable the IN operator and set the delimiter your macro expects.&amp;nbsp; Otherwise the macro will behave differently depending on the setting of the system options with those same names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your point number 2 is explaining about what constitutes a valid use of the IN operator.&amp;nbsp; Basically it is just saying you cannot test if something is in nothing and you cannot test if nothing is in a list.&lt;/P&gt;
&lt;PRE&gt; 1          options minoperator mindelimiter=' ';
 2          %put %eval(x in a b c);
 0
 3          %put %eval(a in a b c);
 1
 4          %put %eval(x in );
 ERROR: Operand missing for IN operator in argument to %EVAL function.
  
 5          %put %eval( in a b c);
 ERROR: Operand missing for IN operator in argument to %EVAL function.
  &lt;/PRE&gt;
&lt;P&gt;Just because you have list of values does not imply that you NEED to use the IN operator.&amp;nbsp; Just like with other things there are other ways to do things.&amp;nbsp; You could use FINDW() function for example.&amp;nbsp; (Note it is hard to use %SYSFUNC() to call the FINDW() function and use only space as the delimiter.)&lt;/P&gt;
&lt;PRE&gt; 6          %put %eval(0&amp;lt;%sysfunc(findw(a b c,x,/,st)));
 0
 7          %put %eval(0&amp;lt;%sysfunc(findw(a b c,a,/,st)));
 1&lt;/PRE&gt;
&lt;P&gt;Note that the FINDW() function does not mind empty arguments.&amp;nbsp; The result is FALSE.&lt;/P&gt;
&lt;PRE&gt; 8          %put %eval(0&amp;lt;%sysfunc(findw(,x,|,st)));
 0
 9          %put %eval(0&amp;lt;%sysfunc(findw(a b c,,|,st)));
 0&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 May 2025 15:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965654#M375922</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-05-03T15:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965655#M375923</link>
      <description>&lt;P&gt;In general, you do not use quotes to surround text in the macro variable value. In general, quotes here are problematic and can make the logic fail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=AU CH AT UR;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is the proper way to do this. If the macro is fed an argument which is AU, then this matches the first "word" of &amp;amp;LIST; in other words, AU (which is the argument of the macro) is an exact match to AU (the first "word" in &amp;amp;LIST).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use quotes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list='AU' 'CH' 'AT' 'UR';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and the macro is fed an argument such as AU without the quotes, then there is no match. Why? Because the text string AU does not match the text in &amp;amp;LIST which is 'AU' in quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AU (a 2 character text string) does not match 'AU' (a four character text string).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So leave the quotes out of the macro variable value in almost all situations.&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 May 2025 15:49:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965655#M375923</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-05-03T15:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965684#M375939</link>
      <description>&lt;P&gt;Does the original question insist on using the IN operator?&amp;nbsp; It would be mildly simpler to use %INDEX:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ctrylist(ctry1);
%let list1=AT AU CA CH;
%put &amp;amp;list1;
%if %index(&amp;amp;list1, &amp;amp;ctry1) %then %do;
   %put &amp;amp;ctry1;
%end;
%else %do;
   %put ERROR: &amp;amp;ctry1 is an invalid country code.;
   %put ERROR: Valid country codes include &amp;amp;list1..;
%end;
%mend ctrylist;
%ctrylist(AU)
%ctrylist(zz) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In general, if you start with simpler tools, adding the complexity of macro language can produce a simpler result.&lt;/P&gt;</description>
      <pubDate>Sun, 04 May 2025 16:48:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965684#M375939</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2025-05-04T16:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965743#M375962</link>
      <description>&lt;P&gt;Related to the original question, there is also the %INM macro which may be of use, and is a lot less typing than creating your own macro to find matches in a text string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro inm(slist,s);
    /* SAS Macro %inm to see if &amp;amp;s is contained in a string or list &amp;amp;slist                 */
    /* Borrowed from https://groups.google.com/forum/#!topic/comp.soft-sys.sas/fWcSDgg11tE */
    %if %sysfunc(indexw(&amp;amp;slist,&amp;amp;s)) gt 0 %then 1 ;
    %else 0;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output of the macro is a&amp;nbsp;1 indicating a match, or a zero indicates no match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example of use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let countrylist=AU AT CH;
%let thiscountry=AT;
%if %inm(&amp;amp;countrylist,&amp;amp;thiscountry) %then %do;
    %put This country is &amp;amp;thiscountry, Match found;
%end;
%let thiscountry=RP;
%if not %inm(&amp;amp;countrylist,&amp;amp;thiscountry) %then %do;
    %put This country is &amp;amp;thiscountry, Match not found;
%end;&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;Sometimes (most times?) asking here in the forum if there is a macro to perform your task is a good first step, rather than just going ahead and trying to write the macro yourself.&lt;/P&gt;</description>
      <pubDate>Mon, 05 May 2025 12:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965743#M375962</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-05-05T12:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965886#M375988</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;thanks very much for your comments, it's a very good question which makes me explore and learn more.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Part of the purpose of the macro in the practice question I mentioned on page 285, Macro Essential1: course note pdf, is like this: 1) using &lt;EM&gt;proc sql&lt;/EM&gt; to generate a country code &lt;EM&gt;&amp;amp;list&lt;/EM&gt; from a dataset, and 2) if the macro parameter value (i.e., the country code) is among the &lt;EM&gt;&amp;amp;list&lt;/EM&gt; then produce a plot, otherwise put an error message. The first time I did that question I made several mistakes and the macro did not work. Then I simplified the code by create a macro through&amp;nbsp;&lt;EM&gt;%let list=;&lt;/EM&gt; instead of using &lt;EM&gt;proc sql&lt;/EM&gt; and made it worked (as you can see from this post). However, today, I run that part of code using the &lt;EM&gt;&amp;amp;list&lt;/EM&gt; produced through &lt;EM&gt;proc sql&lt;/EM&gt;, it did not work again, the code I tried is as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro customerlist(ctry)/minoperator;
proc sql noprint;
select distinct country
   into :ctrylist separated by " "
   from mc1.customers;
quit;
%if &amp;amp;ctry in &amp;amp;ctrylist %then %do;
   title "customers from &amp;amp;ctry";
   proc sgplot data=mc1.customers;
      vbar group;
      yaxis grid;
      where country="&amp;amp;ctry";
   run;
%end;
%else %do;
   %put ERROR: &amp;amp;ctry is an invalid country code.;
   %put ERROR: Valid country codes include &amp;amp;ctrylist..;
%end;
%mend customerlist;
%customerlist(AU);
%customerlist(zz);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The &lt;EM&gt;%customerlist(AU)&lt;/EM&gt; worked well, which produced a plot, but the &lt;EM&gt;%customerlist(zz)&lt;/EM&gt; did not work and there was no error message in the log:&lt;/P&gt;
&lt;PRE&gt; 69         %macro customerlist(ctry)/minoperator;
 70         proc sql noprint;
 71         select distinct country
 72            into :ctrylist separated by " "
 73            from mc1.customers;
 74         quit;
 75         %if &amp;amp;ctry in &amp;amp;ctrylist %then %do;
 76            title "customers from &amp;amp;ctry";
 77            proc sgplot data=mc1.customers;
 78               vbar group;
 79               yaxis grid;
 80               where country="&amp;amp;ctry";
 81            run;
 82         %end;
 83         %else %do;
 84            %put ERROR: &amp;amp;ctry is an invalid country code.;
 85            %put ERROR: Valid country codes include &amp;amp;ctrylist..;
 86         %end;
 87         %mend customerlist;
 88         %customerlist(AU);
NOTE: PROCEDURE SGPLOT used (Total process time):
NOTE: There were 90 observations read from the data set MC1.CUSTOMERS.
       WHERE country='AU';
 89         %customerlist(zz);
 NOTE: PROCEDURE SQL used (Total process time):
NOTE: PROCEDURE SGPLOT used (Total process time):&lt;/PRE&gt;
&lt;P&gt;I did not know why the &lt;EM&gt;&amp;amp;list&lt;/EM&gt; created through &lt;EM&gt;%let list=;&lt;/EM&gt; statement worked but the &lt;EM&gt;&amp;amp;list&lt;/EM&gt; created through &lt;EM&gt;proc sql&lt;/EM&gt; did not work. And in fact another technique that practice question to introduce is the usage of &lt;EM&gt;%superq()&lt;/EM&gt;. I omitted that part because I thought it was too advanced for me and will leave it later. Then I think the reason the macro did not work was I did not use &lt;EM&gt;%superq()&lt;/EM&gt;. After I added it the macro worked, the code and log is as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro customerlist(ctry)/minoperator;
proc sql noprint;
select distinct country
   into :ctrylist separated by " "
   from mc1.customers;
quit;
%if %superq(ctry) in %superq(ctrylist) %then %do;
   title "customers from &amp;amp;ctry";
   proc sgplot data=mc1.customers;
      vbar group;
      yaxis grid;
      where country="&amp;amp;ctry";
   run;
%end;
%else %do;
   %put ERROR: &amp;amp;ctry is an invalid country code.;
   %put ERROR: Valid country codes include &amp;amp;ctrylist..;
%end;
%mend customerlist;
%customerlist(AU);
%customerlist(zz);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt; 69         %macro customerlist(ctry)/minoperator;
 70         proc sql noprint;
 71         select distinct country
 72            into :ctrylist separated by " "
 73            from mc1.customers;
 74         quit;
 75         %if %superq(ctry) in %superq(ctrylist) %then %do;
 76            title "customers from &amp;amp;ctry";
 77            proc sgplot data=mc1.customers;
 78               vbar group;
 79               yaxis grid;
 80               where country="&amp;amp;ctry";
 81            run;
 82         %end;
 83         %else %do;
 84            %put ERROR: &amp;amp;ctry is an invalid country code.;
 85            %put ERROR: Valid country codes include &amp;amp;ctrylist..;
 86         %end;
 87         %mend customerlist;
 88         %customerlist(AU);
 NOTE: PROCEDURE SQL used (Total process time):
 69         %macro customerlist(ctry)/minoperator;
 70         proc sql noprint;
 71         select distinct country
 72            into :ctrylist separated by " "
 73            from mc1.customers;
 74         quit;
 75         %if %superq(ctry) in %superq(ctrylist) %then %do;
 76            title "customers from &amp;amp;ctry";
 77            proc sgplot data=mc1.customers;
 78               vbar group;
 79               yaxis grid;
 80               where country="&amp;amp;ctry";
 81            run;
 82         %end;
 83         %else %do;
 84            %put ERROR: &amp;amp;ctry is an invalid country code.;
 85            %put ERROR: Valid country codes include &amp;amp;ctrylist..;
 86         %end;
 87         %mend customerlist;
 88         %customerlist(AU);
 NOTE: PROCEDURE SQL used (Total process time):
 NOTE: PROCEDURE SGPLOT used (Total process time):
 NOTE: There were 90 observations read from the data set MC1.CUSTOMERS.
       WHERE country='AU';
 89         %customerlist(zz);
 ERROR: zz is an invalid country code.
 ERROR: Valid country codes include AT AU BE CA CH CI DE DK EG ES FI FR GB GR HR IE IL IN 
 IT LT LU MZ NL NO NZ PL PT SE SI TR US YU ZA.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's a very brilliant point you said that "&lt;EM&gt;the macro processor generates code&lt;/EM&gt;" and before writing a macro one should know what the code generated look like. I compared the log using macro debug options for the &lt;EM&gt;%let list=;&lt;/EM&gt; macro and the &lt;EM&gt;proc sql &amp;amp;list&lt;/EM&gt; macro, the logs are as follows. Without&amp;nbsp;&lt;EM&gt;%superq()&lt;/EM&gt;, SAS executed the &lt;EM&gt;proc sgplot&lt;/EM&gt; step, whereas with the &lt;EM&gt;%superq()&lt;/EM&gt;, SAS excuted the &lt;EM&gt;%put ERROR&lt;/EM&gt; message step (see the part marked in red).&lt;/P&gt;
&lt;PRE&gt; 69         %macro customerlist(ctry)/minoperator;
 70         proc sql noprint;
 71         select distinct country
 72            into :ctrylist separated by " "
 73            from mc1.customers;
 74         quit;
 75         %if &amp;amp;ctry in &amp;amp;ctrylist %then %do;
 76            title "customers from &amp;amp;ctry";
 77            proc sgplot data=mc1.customers;
 78               vbar group;
 79               yaxis grid;
 80               where country="&amp;amp;ctry";
 81            run;
 82         %end;
 83         %else %do;
 84            %put ERROR: &amp;amp;ctry is an invalid country code.;
 85            %put ERROR: Valid country codes include &amp;amp;ctrylist..;
 86         %end;
 87         %mend customerlist;
 88         /*%customerlist(AU);*/
 89         options symbolgen mprint mlogic;
 90         %customerlist(zz);
 MLOGIC(CUSTOMERLIST):  Beginning execution.
 MLOGIC(CUSTOMERLIST):  Parameter CTRY has value zz
 MPRINT(CUSTOMERLIST):   proc sql noprint;
 MPRINT(CUSTOMERLIST):   select distinct country into :ctrylist separated by " " from mc1.customers;
 MPRINT(CUSTOMERLIST):   quit;&lt;/PRE&gt;
&lt;DIV class="sasSource"&gt;
&lt;PRE&gt; SYMBOLGEN:  Macro variable CTRY resolves to zz
 SYMBOLGEN:  Macro variable CTRYLIST resolves to AT AU BE CA CH CI DE DK EG ES FI FR GB GR HR IE IL IN &lt;BR /&gt; IT LT LU MZ NL NO NZ PL PT SE SI TR US YU ZA
 &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;MLOGIC(CUSTOMERLIST):  %IF condition &amp;amp;ctry in &amp;amp;ctrylist is TRUE&lt;/STRONG&gt;&lt;/FONT&gt;
 SYMBOLGEN:  Macro variable CTRY resolves to zz
 &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;MPRINT(CUSTOMERLIST):   title "customers from zz";
 MPRINT(CUSTOMERLIST):   proc sgplot data=mc1.customers;
 MPRINT(CUSTOMERLIST):   vbar group;
 MPRINT(CUSTOMERLIST):   yaxis grid;
 SYMBOLGEN:  Macro variable CTRY resolves to zz&lt;/FONT&gt;&lt;/STRONG&gt;
 &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;MPRINT(CUSTOMERLIST):   where country="zz";
 MPRINT(CUSTOMERLIST):   run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;PRE&gt; MLOGIC(CUSTOMERLIST):  Ending execution.
 91         options nosymbolgen nomprint nomlogic;&lt;/PRE&gt;
&lt;PRE&gt; 69         %macro customerlist(ctry)/minoperator;
 70         proc sql noprint;
 71         select distinct country
 72            into :ctrylist separated by " "
 73            from mc1.customers;
 74         quit;
 75         %if %superq(ctry) in %superq(ctrylist) %then %do;
 76            title "customers from &amp;amp;ctry";
 77            proc sgplot data=mc1.customers;
 78               vbar group;
 79               yaxis grid;
 80               where country="&amp;amp;ctry";
 81            run;
 82         %end;
 83         %else %do;
 84            %put ERROR: &amp;amp;ctry is an invalid country code.;
 85            %put ERROR: Valid country codes include &amp;amp;ctrylist..;
 86         %end;
 87         %mend customerlist;
 88         /*%customerlist(AU);*/
 89         options symbolgen mprint mlogic;
 90         %customerlist(zz);
 MLOGIC(CUSTOMERLIST):  Beginning execution.
 MLOGIC(CUSTOMERLIST):  Parameter CTRY has value zz
 MPRINT(CUSTOMERLIST):   proc sql noprint;
 MPRINT(CUSTOMERLIST):   select distinct country into :ctrylist separated by " " from mc1.customers;
 MPRINT(CUSTOMERLIST):   quit;&lt;/PRE&gt;
&lt;PRE&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt; MLOGIC(CUSTOMERLIST):  %IF condition %superq(ctry) in %superq(ctrylist) is FALSE
 MLOGIC(CUSTOMERLIST):  %PUT ERROR: &amp;amp;ctry is an invalid country code.&lt;/FONT&gt;&lt;/STRONG&gt;
 SYMBOLGEN:  Macro variable CTRY resolves to zz
&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt; ERROR: zz is an invalid country code.
 MLOGIC(CUSTOMERLIST):  %PUT ERROR: Valid country codes include &amp;amp;ctrylist..&lt;/FONT&gt;&lt;/STRONG&gt;
 SYMBOLGEN:  Macro variable CTRYLIST resolves to AT AU BE CA CH CI DE DK EG ES FI FR GB GR HR IE IL IN IT &lt;BR /&gt; LT LU MZ NL NO NZ PL PT SE SI TR US YU ZA
 &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ERROR: Valid country codes include AT AU BE CA CH CI DE DK EG ES FI FR GB GR HR IE IL IN IT LT LU MZ NL &lt;BR /&gt; NO NZ PL PT SE SI TR US YU ZA.&lt;/STRONG&gt;&lt;/FONT&gt;
 MLOGIC(CUSTOMERLIST):  Ending execution.
 91         options nosymbolgen nomprint nomlogic;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;I agree with you that many of the "loop" type questions about macro can be solved with by group processing, but here according to my understanding so far, I do not think the requirements can be processed through by group, in that the error message cannot be generated through by group processing.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;Thanks very much &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;again for your valuable input, which enables me learnt more!&lt;/DIV&gt;</description>
      <pubDate>Tue, 06 May 2025 16:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965886#M375988</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-05-06T16:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965887#M375989</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181543"&gt;@svh&lt;/a&gt;&amp;nbsp;thanks a lot for telling this! I have not learnt much about CALL EXECUTE yet, but from your comments I can see that when I am thinking write a macro to solve the problem, maybe I can consider use some CALL EXECUTE first. I will learn to use CALL EXECUTE more later on!&lt;/P&gt;</description>
      <pubDate>Tue, 06 May 2025 16:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/965887#M375989</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-05-06T16:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/966012#M376009</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;although I cannot access github, thanks a lot for telling me this!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the pre-debugged macro you mentioned was to use the &lt;EM&gt;&amp;amp;parmerr&lt;/EM&gt; combined with the &lt;EM&gt;%parmv&lt;/EM&gt; (which has two parameters, one is the parameter of the outside macro such as &lt;EM&gt;ctry1&lt;/EM&gt;, the other is the list of values such as &lt;EM&gt;_val=AT AU CA CH&lt;/EM&gt;), if the condition of &lt;EM&gt;&amp;amp;parmerr&lt;/EM&gt; is matched then put error message, if not then execute the code to produce what I want. Does this pre-debugged macro need to be downloaded from github? Does SAS has any built-in macro or options (I guess not‌‌&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;) I can use for macro debugging (aside from the handy and simple options such as&amp;nbsp;&lt;EM&gt;mlogic, mprint,&lt;/EM&gt; and &lt;EM&gt;symbolgen&lt;/EM&gt;) or options like &lt;EM&gt;validate&lt;/EM&gt; in &lt;EM&gt;proc sql&lt;/EM&gt; (in fact I personally do not think using &lt;EM&gt;validate&lt;/EM&gt; helps much because when there is syntax error the log will give me error message even if I do not use &lt;EM&gt;validate&lt;/EM&gt;, but at least when my syntax is ok it helps confirm that I do not have syntax error. On the other hand, in fact, when my code does not run through, I am more inclined to inspect all the details of the code by myself, as using extra tools sometimes make things more complex):&lt;/P&gt;
&lt;PRE&gt; 69         proc sql number;
 70         validate
 71         select make,origin,msrp
 72            from sashelp.cars
 73            where msrp&amp;lt;(select mean(msrp)+2*std(msrp)
 74                         from sashelp.cars);
 NOTE: PROC SQL statement has valid syntax.
 75         quit;&lt;/PRE&gt;
&lt;PRE&gt; 76         proc sql number;
 77         validate
 78         select make,origin,msrp
 79            from sashelp.cars
 80            where msrp&amp;lt;(select mean(msrp)+2*std(msrp)
 81                         from sashelp.cars;
                                             _
                                             79
 ERROR 79-322: Expecting a ).
 
 NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
 81                                           )
                                              _
                                              180
 ERROR 180-322: Statement is not valid or it is used out of proper order.
 
 82         quit;
 NOTE: The SAS System stopped processing this step because of errors.&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 May 2025 18:40:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/966012#M376009</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-05-07T18:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/966039#M376013</link>
      <description>&lt;P&gt;Validation of the inputs to your macro program has little to do with whatever that SQL VALIDATE statement does.&amp;nbsp; They just happen to be using the same verb, which is a common issue with computer terminology which picks (sometimes seemingly random) words and gives them special meanings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would assume that the VALIDATE statement you played with in SQL is of some value to someone that is writing code that programmatically generates SQL statements and wants to test if the generated syntax is valid before actually running them.&amp;nbsp; But that is not something I have ever needed to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can go look at the PARMV macro in GITHUB on some other computer (or your phone for that matter).&amp;nbsp; Read the header to see if what it can do for you has any value for you now (or perhaps in the future for some other project.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To learn more about how to COMPILE a macro definition so that you can use it in your program check the SAS documentation.&amp;nbsp; You might want to look at the section on autocall macro libraries.&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 03:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/966039#M376013</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-05-08T03:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Thoughts and questions: why this kind of macro is so difficult to debug.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/966177#M376048</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;thanks very much for telling me the usage of &lt;EM&gt;%index&lt;/EM&gt;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;, I tested it on the code and it works brightly&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;, saves a lot of headache&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;. The materials did not insist on using IN operator, it was to let leaners practice the usage of &lt;EM&gt;MINOPERATOR&lt;/EM&gt;. But I'll just use &lt;EM&gt;%index(&amp;amp;valuelist,&amp;amp;parametervalue)&lt;/EM&gt; from now on, it's handy and simple. The code I tested is as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro customerlist(ctry)/minoperator;
proc sql noprint;
select distinct country
   into :ctrylist separated by " "
   from mc1.customers;
quit;
%if %index(&amp;amp;ctrylist,&amp;amp;ctry) %then %do;
   title "customers from &amp;amp;ctry";
   proc sgplot data=mc1.customers;
      vbar group;
      yaxis grid;
      where country="&amp;amp;ctry";
   run;
%end;
%else %do;
   %put ERROR: &amp;amp;ctry is an invalid country code.;
   %put ERROR: Valid country codes include &amp;amp;ctrylist..;
%end;
%mend customerlist;
%customerlist(AU);
options symbolgen mprint mlogic;
%customerlist(zz);
options nosymbolgen nomprint nomlogic;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt; 71         %macro customerlist(ctry)/minoperator;
 72         proc sql noprint;
 73         select distinct country
 74            into :ctrylist separated by " "
 75            from mc1.customers;
 76         quit;
 77         %if %index(&amp;amp;ctrylist,&amp;amp;ctry) %then %do;
 78            title "customers from &amp;amp;ctry";
 79            proc sgplot data=mc1.customers;
 80               vbar group;
 81               yaxis grid;
 82               where country="&amp;amp;ctry";
 83            run;
 84         %end;
 85         %else %do;
 86            %put ERROR: &amp;amp;ctry is an invalid country code.;
 87            %put ERROR: Valid country codes include &amp;amp;ctrylist..;
 88         %end;
 89         %mend customerlist;
 90         %customerlist(AU);&lt;/PRE&gt;
&lt;PRE&gt; 91         options symbolgen mprint mlogic;
 92         %customerlist(zz);
 MLOGIC(CUSTOMERLIST):  Beginning execution.
 MLOGIC(CUSTOMERLIST):  Parameter CTRY has value zz
 MPRINT(CUSTOMERLIST):   proc sql noprint;
 MPRINT(CUSTOMERLIST):   select distinct country into :ctrylist separated by " " &lt;BR /&gt; from mc1.customers;
 MPRINT(CUSTOMERLIST):   quit;&lt;/PRE&gt;
&lt;PRE&gt; SYMBOLGEN:  Macro variable CTRYLIST resolves to AT AU BE CA CH CI DE DK EG ES FI FR GB GR HR IE IL IN &lt;BR /&gt; IT LT LU MZ NL NO NZ PL PT SE SI TR US YU ZA
 SYMBOLGEN:  Macro variable CTRY resolves to zz
&lt;FONT color="#3366FF"&gt; MLOGIC(CUSTOMERLIST):  %IF condition %index(&amp;amp;ctrylist,&amp;amp;ctry) is FALSE
 MLOGIC(CUSTOMERLIST):  %PUT ERROR: &amp;amp;ctry is an invalid country code.&lt;/FONT&gt;
 SYMBOLGEN:  Macro variable CTRY resolves to zz
 &lt;FONT color="#FF0000"&gt;ERROR: zz is an invalid country code.&lt;/FONT&gt;
 &lt;FONT color="#3366FF"&gt;MLOGIC(CUSTOMERLIST):  %PUT ERROR: Valid country codes include &amp;amp;ctrylist..&lt;/FONT&gt;
 SYMBOLGEN:  Macro variable CTRYLIST resolves to AT AU BE CA CH CI DE DK EG ES FI FR GB GR HR IE IL &lt;BR /&gt; IN IT LT LU MZ NL NO NZ PL PT SE SI TR US YU ZA
 &lt;FONT color="#FF0000"&gt;ERROR: Valid country codes include AT AU BE CA CH CI DE DK EG ES FI FR GB GR HR IE IL IN IT LT LU MZ &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt; NL NO NZ PL PT SE SI TR US YU ZA.&lt;/FONT&gt;
 MLOGIC(CUSTOMERLIST):  Ending execution.
 93         options nosymbolgen nomprint nomlogic;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 May 2025 16:50:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thoughts-and-questions-why-this-kind-of-macro-is-so-difficult-to/m-p/966177#M376048</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-05-09T16:50:56Z</dc:date>
    </item>
  </channel>
</rss>

