<?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: Macro loop problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80405#M17310</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;it would be easier to do the same thing in a data step.&lt;/P&gt;&lt;P&gt;If it is prod code why does it need to change? &lt;/P&gt;&lt;P&gt;My suggestion is&lt;/P&gt;&lt;P&gt;Data null ;&lt;/P&gt;&lt;P&gt;Call execute( '%nrstr( %%p)ut new condition is case when ( ' ) ;&lt;/P&gt;&lt;P&gt;Do until( last.label3) ;&lt;/P&gt;&lt;P&gt;Set your.data;&lt;/P&gt;&lt;P&gt;By label1 label2 label3 ;&lt;/P&gt;&lt;P&gt;Call execute( '( ' !! condition !! ' ) ' ) ;&lt;/P&gt;&lt;P&gt;If not last.label3 then&lt;/P&gt;&lt;P&gt;Call execute( ' or ' );&lt;/P&gt;&lt;P&gt;End ;&lt;/P&gt;&lt;P&gt;Call execute( ' ) ' ) ;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Jul 2013 10:00:54 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2013-07-16T10:00:54Z</dc:date>
    <item>
      <title>Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80402#M17307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Guys, I am doing a concatenation reading data one observation at a time. So my data and code is as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input @1 label1 $ @3 label2 $ @5 label3 $1. @7 condition $;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;a d&amp;nbsp;&amp;nbsp;&amp;nbsp; p code1&lt;/P&gt;&lt;P&gt;a d&amp;nbsp;&amp;nbsp;&amp;nbsp; p code7&lt;/P&gt;&lt;P&gt;b e&amp;nbsp;&amp;nbsp;&amp;nbsp; q code2&lt;/P&gt;&lt;P&gt;b e&amp;nbsp;&amp;nbsp;&amp;nbsp; q code3&lt;/P&gt;&lt;P&gt;c p&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; code4&lt;/P&gt;&lt;P&gt;d a&amp;nbsp;&amp;nbsp;&amp;nbsp; r code5&lt;/P&gt;&lt;P&gt;d a&amp;nbsp;&amp;nbsp;&amp;nbsp; r code6&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options nomlogic ;&lt;/P&gt;&lt;P&gt;%macro rules (table_name);&lt;/P&gt;&lt;P&gt;/* open the table*/&lt;/P&gt;&lt;P&gt;%let table_id=%sysfunc(open(&amp;amp;table_name,i));&lt;/P&gt;&lt;P&gt;/* fetch the first record */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let rc=%sysfunc(fetch(&amp;amp;table_id));&lt;/P&gt;&lt;P&gt;%if &amp;amp;rc ne 0 %then &lt;/P&gt;&lt;P&gt;%do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put something is wrong ...;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%else &lt;/P&gt;&lt;P&gt;%do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* read data for first record */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let label1=%sysfunc(getvarc(&amp;amp;table_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %sysfunc(varnum(&amp;amp;table_id,label1))));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let label2=%sysfunc(getvarc(&amp;amp;table_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %sysfunc(varnum(&amp;amp;table_id,label2))));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let label3=%sysfunc(getvarc(&amp;amp;table_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %sysfunc(varnum(&amp;amp;table_id,label3))));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let condition=%sysfunc(getvarc(&amp;amp;table_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %sysfunc(varnum(&amp;amp;table_id,condition))));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Save values and iterate again */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_label1=&amp;amp;label1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_label2=&amp;amp;label2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_label3=&amp;amp;label3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_condition=&amp;amp;condition;&lt;/P&gt;&lt;P&gt;/* Read remaining records */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let rc=%sysfunc(fetch(&amp;amp;table_id));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do %while (&amp;amp;rc eq 0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let label1=%sysfunc(getvarc(&amp;amp;table_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %sysfunc(varnum(&amp;amp;table_id,label1))));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let label2=%sysfunc(getvarc(&amp;amp;table_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %sysfunc(varnum(&amp;amp;table_id,label2))));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let label3=%sysfunc(getvarc(&amp;amp;table_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %sysfunc(varnum(&amp;amp;table_id,label3))));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let condition=%sysfunc(getvarc(&amp;amp;table_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %sysfunc(varnum(&amp;amp;table_id,condition))));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if (&amp;amp;prev_label1 eq &amp;amp;label1)and (&amp;amp;prev_label2 eq &amp;amp;label2) and (&amp;amp;prev_label3 eq &amp;amp;label3) %then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let new_condition=case when &amp;amp;prev_condition or (&amp;amp;condition);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put new_condition is &amp;amp;new_condition;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_label1=&amp;amp;label1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_label2=&amp;amp;label2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_label3=&amp;amp;label3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_condition=&amp;amp;condition;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let new_condition=case when &amp;amp;prev_condition or (&amp;amp;condition);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put new_condition is &amp;amp;new_condition;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let rc=%sysfunc(fetch(&amp;amp;table_id));&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let rc=%sysfunc(close(&amp;amp;table_id));&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%rules(have);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What i want in output is&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;new_condition is case when ((code1) or (code7))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;new_condition is case when ((code2) or (code3))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;new_condition is case when ((code2) or (code3))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;new_condition is case when ((code4))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;new_condition is case when ((code5) or (code6))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, my last observation and first observation gets lost in loop. Please share your views.. Thanks in advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 03:31:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80402#M17307</guid>
      <dc:creator>forumsguy</dc:creator>
      <dc:date>2013-07-16T03:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80403#M17308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why force it into the macro language?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 07:18:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80403#M17308</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-07-16T07:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80404#M17309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Peter C.. Thats my requirement. This is prod code and cant be changed.. Hence i am stuck with this.. :smileycry:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 08:37:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80404#M17309</guid>
      <dc:creator>forumsguy</dc:creator>
      <dc:date>2013-07-16T08:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80405#M17310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;it would be easier to do the same thing in a data step.&lt;/P&gt;&lt;P&gt;If it is prod code why does it need to change? &lt;/P&gt;&lt;P&gt;My suggestion is&lt;/P&gt;&lt;P&gt;Data null ;&lt;/P&gt;&lt;P&gt;Call execute( '%nrstr( %%p)ut new condition is case when ( ' ) ;&lt;/P&gt;&lt;P&gt;Do until( last.label3) ;&lt;/P&gt;&lt;P&gt;Set your.data;&lt;/P&gt;&lt;P&gt;By label1 label2 label3 ;&lt;/P&gt;&lt;P&gt;Call execute( '( ' !! condition !! ' ) ' ) ;&lt;/P&gt;&lt;P&gt;If not last.label3 then&lt;/P&gt;&lt;P&gt;Call execute( ' or ' );&lt;/P&gt;&lt;P&gt;End ;&lt;/P&gt;&lt;P&gt;Call execute( ' ) ' ) ;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 10:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80405#M17310</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-07-16T10:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80406#M17311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Look into using %SYSCALL SET(...) statement.&amp;nbsp; This will eliminate the need to pull the variable values into macro variables.&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000127856.htm" style="font-size: 10pt; line-height: 1.5em;" title="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000127856.htm"&gt;SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 13:23:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80406#M17311</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-07-16T13:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80407#M17312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Forumsguy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure this is what you are looking for based on the output you said you wanted, however, I assumed from the code that your intentions were cases where all 3 labels are identical to be output on a single line and only once. I simply added a tracker of "single codes" and slightly adapted your %put statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, if what I did was not what you were looking for, here is some clues as to why your output is odd. The %put outside at the end of your do while effectively duplicates all %put in the case where labels are equal. If it is your way around to douple parse such cases, you may as well just duplicate the put statement in your do segment rather than use one outside. This will allow you to control the %else statement with a boolean-like variable telling you if you were ongoing a "single label" versus a pair (or more) of labels. In other words, it would be best if you had your %put statements each within the do/else and not one outside.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not entirely sure why you mentionned you were "losing" the first and last record of your DS with the example you've mentionned as to what output you really want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you wanted an output like&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;new_condition is case when ((code1) or (code7))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;new_condition is case when ((code1) or (code7))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;new_condition is case when ((code2) or (code3))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;new_condition is case when ((code2) or (code3))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;new_condition is case when ((code4))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;new_condition is case when ((code5) or (code6))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;new_condition is case when ((code5) or (code6))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is, effectively duplicating all including first and last observations, you can simply copy past the %put statement in the labels are equal %do segment in the code I provided.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vincent&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 13:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80407#M17312</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-07-16T13:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80408#M17313</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks like you are trying to mimic FIRST. processing in macro code?&lt;/P&gt;&lt;P&gt;Try this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;input label1 $ label2 $ label3 $ condition $ ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;a d&amp;nbsp;&amp;nbsp;&amp;nbsp; p code1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;a d&amp;nbsp;&amp;nbsp;&amp;nbsp; p code7&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;b e&amp;nbsp;&amp;nbsp;&amp;nbsp; q code2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;b e&amp;nbsp;&amp;nbsp;&amp;nbsp; q code3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;c p&amp;nbsp;&amp;nbsp;&amp;nbsp; . code4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;d a&amp;nbsp;&amp;nbsp;&amp;nbsp; r code5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;d a&amp;nbsp;&amp;nbsp;&amp;nbsp; r code6&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro rules (table_name);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %local label1 label2 label3 condition ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %local prev_label1 prev_label2 prev_label3 prev_condition ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %local table_id rc n first new_condition ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;/* open the table */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let table_id=%sysfunc(open(&amp;amp;table_name,i));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%if not &amp;amp;table_id %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %put Unable to open &amp;amp;table_name ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %goto quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;/* Link dataset variables to matching macro variables */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%syscall set(table_id);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;/* Read all observations */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let n=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%do %while (not %sysfunc(fetch(&amp;amp;table_id)));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %let n=%eval(&amp;amp;n + 1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %let first=%eval( &amp;amp;n=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; or %superq(prev_label1) ne %superq(label1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; or %superq(prev_label2) ne %superq(label2)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; or %superq(prev_label3) ne %superq(label3)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;/* Build up new_condition */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %if &amp;amp;first %then %let new_condition=&amp;amp;condition;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %else %let new_condition=&amp;amp;new_condition or &amp;amp;condition ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %put n=&amp;amp;n first=&amp;amp;first new_condition is case when (&amp;amp;new_condition) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;/* Save values for next iteration */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_label1=%superq(label1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_label2=%superq(label2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_label3=%superq(label3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_condition=%superq(condition);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let rc= %sysfunc(close(&amp;amp;table_id));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%quit:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%rules(have);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;n=1 first=1 new_condition is case when (code1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;n=2 first=0 new_condition is case when (code1 or code7)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;n=3 first=1 new_condition is case when (code2)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;n=4 first=0 new_condition is case when (code2 or code3)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;n=5 first=1 new_condition is case when (code4)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;n=6 first=1 new_condition is case when (code5)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;n=7 first=0 new_condition is case when (code5 or code6)&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 14:24:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80408#M17313</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-07-16T14:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80409#M17314</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Adding both FIRST. and LAST. is a little harder.&lt;/P&gt;&lt;P&gt;Try this.&amp;nbsp; I also added () around the values of the CONDITION variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro rules (table_name);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %local label1 label2 label3 condition ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %local prev_label1 prev_label2 prev_label3 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %local table_id rc n first new_condition ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;/* open the table */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let table_id=%sysfunc(open(&amp;amp;table_name,i));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%if not &amp;amp;table_id %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %put Unable to open &amp;amp;table_name ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %goto quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;/* Link dataset variables to macro variables */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%syscall set(table_id);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let n=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%do %while (not %sysfunc(fetch(&amp;amp;table_id)));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %let n=%eval(&amp;amp;n + 1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %let first=%eval( &amp;amp;n=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; or %superq(prev_label1) ne %superq(label1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; or %superq(prev_label2) ne %superq(label2)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; or %superq(prev_label3) ne %superq(label3)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;/* Build up new_condition and emit previous condition */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %if &amp;amp;first %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if (&amp;amp;n &amp;gt; 1) %then %put new_condition is case when (&amp;amp;new_condition) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let new_condition=(%trim(&amp;amp;condition));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %else %let new_condition=&amp;amp;new_condition or (%trim(&amp;amp;condition)) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;/* Save values for next iteration */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_label1=%superq(label1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_label2=%superq(label2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prev_label3=%superq(label3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let rc= %sysfunc(close(&amp;amp;table_id));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%if (&amp;amp;n) %then %put new_condition is case when (&amp;amp;new_condition) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%else %put No Conditions;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%quit:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%rules(have);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;new_condition is case when ((code1) or (code7))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;new_condition is case when ((code2) or (code3))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;new_condition is case when ((code4))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;new_condition is case when ((code5) or (code6))&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 14:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80409#M17314</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-07-16T14:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80410#M17315</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@TOM.. Amazing... its working .. However, it gives me one minor error....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The keyword parameter&amp;nbsp; was not defined with the macro... do you have idea what it could be for ?? I guess its related to SAS installation folder&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 15:24:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80410#M17315</guid>
      <dc:creator>forumsguy</dc:creator>
      <dc:date>2013-07-16T15:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80411#M17316</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom...Got it corrected.. Guess I need to read on Syscall set ... it seems magical ....thanks a lot guys ..so many ways to solve the problem.... Awesome...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 15:32:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80411#M17316</guid>
      <dc:creator>forumsguy</dc:creator>
      <dc:date>2013-07-16T15:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80412#M17317</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Errors related to keyword parameter not defined usually point to a call in a macro like&lt;/P&gt;&lt;P&gt;%dummy(parm1=somevalue), but when the macro was defined as in %macro dummy([parameters]) did not include parm1 with the = . Without the = the parameter is positional and not referenced as (parm1=).&lt;/P&gt;&lt;P&gt;If you tried calling Tom's macro with %rules(table_name=) that would be the cause.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 15:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80412#M17317</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-07-16T15:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80413#M17318</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Most likely there are equal signs in CONDITION and it is confusing to call to %TRIM().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Convert&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;%trim(&amp;amp;condition)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; to &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;condition &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;or to &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;&amp;nbsp; &lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;%trim(%superq(condition))&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 15:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80413#M17318</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-07-16T15:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80414#M17319</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Pity a data step isn't an option. It protects so well against values like condition becoming confused with process.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 19:37:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80414#M17319</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-07-16T19:37:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80415#M17320</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Tom.. There is also one dot in my condition. How should I resolve it .. One of my conditions is &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;val_write_off ^=.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since superq doesnot unmask it .. is there any other way.. I tried with other functions as well..However couldnt find out solution....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 14:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80415#M17320</guid>
      <dc:creator>forumsguy</dc:creator>
      <dc:date>2013-07-17T14:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80416#M17321</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use missing() function&lt;/P&gt;&lt;P&gt;Or&lt;/P&gt;&lt;P&gt;Use &lt;/P&gt;&lt;P&gt;Not column is null&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 14:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80416#M17321</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-07-17T14:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80417#M17322</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not just give up on that old %TRIM() macro and use %SYSFUNC() to call the TRIM() function.&amp;nbsp; That will not care about equal signs or periods.&amp;nbsp; If the value of CONDITION does not work for TRIM() function then it will also not work when used as code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;/* Build up new_condition and emit previous condition */&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; %if &amp;amp;first %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if (&amp;amp;n &amp;gt; 1) %then %put new_condition is case when (&amp;amp;new_condition) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let new_condition=(%sysfunc(trim(&amp;amp;condition)));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; %else %let new_condition=&amp;amp;new_condition or (%sysfunc(trim(&amp;amp;condition))) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 22:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80417#M17322</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-07-17T22:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80418#M17323</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Peter,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was just curious how to get this code working with a slight modification..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Like&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data _null_ ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Call execute('case when&amp;nbsp; label1='||label1||' 'and label2='||label2|| 'and label3'='||label3'and''( ' ) ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Do until( last.label3) ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Set have;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;By label1 label2 label3 ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Call execute( '( ' !! CONDITION !! ' ) ' ) ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If not last.label3 then&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Call execute( ' or ' );&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;End ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Call execute( ' ) ' ) ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;But its giving errors.. can you please help me out with solution of this??? thanks in advance and helping me to learn new things&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Jul 2013 10:24:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80418#M17323</guid>
      <dc:creator>forumsguy</dc:creator>
      <dc:date>2013-07-19T10:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80419#M17324</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why use LABEL1&amp;nbsp; before the SET statement?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would suggest placing that definition of the "fixed part" after the BY statement and only when FIRST.LABEL3&lt;/P&gt;&lt;P&gt;Do you need me to write the syntax?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Jul 2013 14:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80419#M17324</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-07-19T14:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80420#M17325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not the complete code.. just call execute&amp;nbsp; first part only which contains the and statement.&amp;nbsp; It would be of great help.. if you guide.. since I am getting different errors every time ...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Jul 2013 17:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80420#M17325</guid>
      <dc:creator>forumsguy</dc:creator>
      <dc:date>2013-07-19T17:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80421#M17326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Arial, sans-serif;"&gt;Ok&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Arial, sans-serif;"&gt;here is how to investigate the problem(s) with the code you posted earlier.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Arial, sans-serif;"&gt;Perhaps the problems all lay in the line.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Call execute('case when&amp;nbsp; label1='||label1||' 'and label2='||label2|| 'and label3'='||label3'and''( ' ) ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Arial, sans-serif;"&gt;rearrange it with fixed pitch text and white space to align it&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;It could be rearranged as&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 9pt;"&gt;Call execute(&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 9pt;"&gt;'case&amp;nbsp; when label1='&lt;/SPAN&gt; &lt;SPAN lang="EN-US" style="font-size: 9pt;"&gt;|| label1 ||'&amp;nbsp; &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN lang="EN-US" style="font-size: 9pt;"&gt;'and label2=' || label2 ||&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN lang="EN-US" style="font-size: 9pt;"&gt;'and label3'='|| label3 'and' '( &lt;STRONG style="font-family: 'courier new', courier;"&gt;&lt;SPAN lang="EN-US" style="font-size: 9pt;"&gt;'&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN lang="EN-US" style="font-size: 9pt;"&gt; )&lt;/SPAN&gt; &lt;SPAN lang="EN-US" style="font-size: 9pt;"&gt;;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;Now I can see the problem!&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;The code won’t align properly because the quotes are mis-placed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;. &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;I expect you understand the difference between constants which appear within quotes, and the names of variables.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;And perhaps you just find it difficult to adapt other peoples’ code. That earlier code of mine was untested and bug-infested &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;Because there are no comparisons (GE, LT, EQ, etc.) in your code above, the only possible problem caused by adding that “white space” is that you will get more white space on your output. However, it helps to spot where the code has become “unbalanced”. &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;I consider the layout of code the biggest assistance to de-bugging.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;Next time your code gives you a problem, lay it out to match the processing you need – stage by stage. Only once you are satisfied that all the piece you need are in place, will you be ready to collapse white space, functions and statements.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;Layout is a big part of how I debug/analyse programs. You may have better ideas.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;Once that quoting is properly placed, you’ll find you need to prefix the call execute() output (which goes into the submit stream immediately after this step completes because that is the way call execute() works). I would suggest an asterisk because then the strings generated will appear within a comment.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;Much improvement is needed to make the whole thing work. Having gone through a testing exercise, I’m beginning to realise that my (untested) suggestion in the earlier posting was missing a few features, (like:1&amp;nbsp; generating a closing semicolon, 2:&amp;nbsp; STOPping at the right point).&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;Rather than populate a macro variable directly through call execute(), I’m beginning to see a better solution might write the logic code to a file. That could then be invoked by %include.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;Mostly the change is just a matter of replacing call execute() with PUT statements.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;Here is one I prepared with generated sql code in mind&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;*';&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;*";&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;*/; * clean up unbalanced quotes;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;Data&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;_null_&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;file&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'generated logic code.txt'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; enough &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;DO&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;PUT&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;' END ; '&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;STOP&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;END&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;* data step iteration for a row ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; _n_ = &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;PUT&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'%LET LOGIC_CODE= CASE '&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Do&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;until&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;( last.label3) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;* do loop iteration for each condition ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;* i.e. each condition within one set of label1-3 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Set&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; have end= enough ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;By&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; label1 label2 label3 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;* on first for a set of label1-3 report those labels ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;If&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; first.label3 &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;PUT&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;' WHEN '&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; label1= &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'&amp;amp; '&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label2= &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'&amp;amp; '&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label3= &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'&amp;amp; '&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'('&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;* "named" put style with those "=" is really helpful ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;FORMAT&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; LABEL1-LABEL3 &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: teal; background: white;"&gt;$QUOTE200.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;* the FORMAT statement directs the PUT to quote the values of label1-3 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;* now for each CONDITION, report it with ( parentheses ) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;PUT&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'( '&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; CONDITION&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;' ) '&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;* if not last for a set of label1-3 need to say OR ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;If&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; not last.label3 &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;PUT&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;' OR '&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;End&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;* now after all conditions reported, close with another ) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;PUT&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;' )&amp;nbsp; '&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;Run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;SPAN style="color: #008000; font-family: 'Courier New'; background-color: #ffffff;"&gt;* now check the generated text ;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;PROC&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;FSLIST&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; FILE=&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'generated logic code.txt'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;RUN&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="SASCode"&gt;&lt;SPAN lang="EN-US" style="font-family: 'Arial','sans-serif';"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Jul 2013 18:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-problem/m-p/80421#M17326</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-07-20T18:13:36Z</dc:date>
    </item>
  </channel>
</rss>

