<?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 How do I solve this problem ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846242#M334557</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset1&lt;/P&gt;&lt;P&gt;ProductId Account_Num Flag1 Flag2 Flag3&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;89123&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;98571&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 86754&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset2&lt;/P&gt;&lt;P&gt;Product_Id&amp;nbsp; R_Code Order&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 45&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 80&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Macros i have&amp;nbsp; conditions&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;%macro 50;&lt;BR /&gt;if&amp;nbsp;Product_Id in ('1') then do ;&lt;BR /&gt;if Flag1 in ('Y') then do;&lt;BR /&gt;status_code ='50';&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;%mend 50;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;%macro 45;&lt;BR /&gt;if&amp;nbsp;Product_Id in ('1') then do ;&lt;BR /&gt;if Flag2 in ('Y') then do;&lt;BR /&gt;status_code ='45';&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;%mend 45;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here&amp;nbsp; for example - acct_num&amp;nbsp;89123 qualify for status_code 50 and 45 as per the conditions specified in macros. But in output dataset i should only get the status_code to be updated to 50 to this particular account as it's order is 1. We have to get the status_code which is first matching based on order. In the same way all the accounts should get updated with correct status_code.&lt;/P&gt;&lt;P&gt;Output Dataset&lt;/P&gt;&lt;P&gt;Product_id&amp;nbsp; Account_Num Flag1 Flag2 Flag3 Status_Code&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;89123&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;98571&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 45&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 86754&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 50&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone tell me how to solve this?&lt;/P&gt;</description>
    <pubDate>Fri, 25 Nov 2022 05:32:51 GMT</pubDate>
    <dc:creator>sasuser_01</dc:creator>
    <dc:date>2022-11-25T05:32:51Z</dc:date>
    <item>
      <title>How do I solve this problem ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846242#M334557</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset1&lt;/P&gt;&lt;P&gt;ProductId Account_Num Flag1 Flag2 Flag3&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;89123&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;98571&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 86754&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset2&lt;/P&gt;&lt;P&gt;Product_Id&amp;nbsp; R_Code Order&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 45&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 80&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Macros i have&amp;nbsp; conditions&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;%macro 50;&lt;BR /&gt;if&amp;nbsp;Product_Id in ('1') then do ;&lt;BR /&gt;if Flag1 in ('Y') then do;&lt;BR /&gt;status_code ='50';&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;%mend 50;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;%macro 45;&lt;BR /&gt;if&amp;nbsp;Product_Id in ('1') then do ;&lt;BR /&gt;if Flag2 in ('Y') then do;&lt;BR /&gt;status_code ='45';&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;%mend 45;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here&amp;nbsp; for example - acct_num&amp;nbsp;89123 qualify for status_code 50 and 45 as per the conditions specified in macros. But in output dataset i should only get the status_code to be updated to 50 to this particular account as it's order is 1. We have to get the status_code which is first matching based on order. In the same way all the accounts should get updated with correct status_code.&lt;/P&gt;&lt;P&gt;Output Dataset&lt;/P&gt;&lt;P&gt;Product_id&amp;nbsp; Account_Num Flag1 Flag2 Flag3 Status_Code&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;89123&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;98571&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 45&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 86754&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 50&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone tell me how to solve this?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2022 05:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846242#M334557</guid>
      <dc:creator>sasuser_01</dc:creator>
      <dc:date>2022-11-25T05:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I solve this problem ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846256#M334565</link>
      <description>&lt;P&gt;How many macro with logic do you have? Why is the logic contained in macros?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2022 08:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846256#M334565</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-25T08:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I solve this problem ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846308#M334583</link>
      <description>That is the requirement. We should keep conditions only in macro. And for every if condition one specific macro should be created.</description>
      <pubDate>Fri, 25 Nov 2022 12:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846308#M334583</guid>
      <dc:creator>sasuser_01</dc:creator>
      <dc:date>2022-11-25T12:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I solve this problem ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846309#M334584</link>
      <description>And there are 50 plus macros .</description>
      <pubDate>Fri, 25 Nov 2022 12:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846309#M334584</guid>
      <dc:creator>sasuser_01</dc:creator>
      <dc:date>2022-11-25T12:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I solve this problem ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846378#M334609</link>
      <description>&lt;P&gt;So is there are rule that if an account qualifies for more than one status, the highest status code is applied?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also macro names need to be valid SAS names and they can't start with a number.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2022 21:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846378#M334609</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-11-25T21:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I solve this problem ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846380#M334610</link>
      <description>&lt;P&gt;The data you presented show that Product_ID and Flag2 don't exist in the same data set.&amp;nbsp; How do you propose to put the data together so that a macro could be applied?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you want to name your macros?&amp;nbsp; Clearly "50" and "45" are invalid names for a macro?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2022 21:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846380#M334610</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-11-25T21:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I solve this problem ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846381#M334611</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437292"&gt;@sasuser_01&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;And there are 50 plus macros .&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And let me guess, they only differ in the value to be compared to? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Using arguments to macros&amp;nbsp; wouldn't be allowed?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2022 21:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846381#M334611</guid>
      <dc:creator>fja</dc:creator>
      <dc:date>2022-11-25T21:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I solve this problem ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846408#M334615</link>
      <description>Dataset 1 has product_id and flag variables. I will call macros in dataset1. And also I will change macros to m50 and m45 etc. My thought is to keep all the updated status codes in a array in output dataset. And then to select the value in an array according to the order mentioned in dataset 2.</description>
      <pubDate>Sat, 26 Nov 2022 04:23:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846408#M334615</guid>
      <dc:creator>sasuser_01</dc:creator>
      <dc:date>2022-11-26T04:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I solve this problem ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846412#M334616</link>
      <description>&lt;P&gt;I do not fully understand the idea behind your macros and the intended logic. The macros given just act on product_id 1 ... what about the others? What shall be the status_code if the flag tested for is different from Y?&lt;/P&gt;
&lt;P&gt;Have I missed something?&lt;/P&gt;
&lt;P&gt;--fja&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;edit:&lt;/STRONG&gt; To be more precise: Wouldn't simply merging in the first matching observation from dataset2 an alternative to the use of macros (code untested):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outTable; 
  merge dataset1 dataset2;
  by Product_Id;
  if first.Product_Id = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Nov 2022 09:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846412#M334616</guid>
      <dc:creator>fja</dc:creator>
      <dc:date>2022-11-26T09:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I solve this problem ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846432#M334618</link>
      <description>&lt;P&gt;I don't think you have totally explained what you are doing.&lt;/P&gt;
&lt;P&gt;It looks like the second dataset is what is driving the logic.&amp;nbsp; So let's call that dataset the RULES.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rules;
  input Product_Id Order R_Code ;
cards;
1 1 50
1 2 45
2 1 80
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the first dataset seems to be the actual data.&amp;nbsp; Let's call that ORDERS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data orders ;
  input Account_Num Product_Id (Flag1-Flag2) (:$1.);
cards;
89123  1  Y Y 
98571  1  N Y 
86754  2  Y Y 
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And now reading between the lines of your IF/THEN statements it looks like you want to use the FLAG1 status with the ORDER=1 rule.&amp;nbsp; So it would be better to transpose the ORDERS dataset to have one observation per FLAG.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data orders_tall;
  set orders;
  array _flag flag1-flag2 ;
  do order=1 to dim(_flag);
     flag=_flag[order];
     output;
  end;
  drop flag1-flag2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1669489260534.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77733i5AC0A1567B23A3CA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1669489260534.png" alt="Tom_0-1669489260534.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Now we can merge the data by PRODUCT_ID and ORDER .&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select a.*
       , b.r_code
  from orders_tall a 
  left join rules b
    on a.product_id=b.product_id
    and a.order = b.order 
    and a.flag='Y'
  order by a.account_num,a.product_id,a.order
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_1-1669489621036.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77734iCF4D6E860F62FD8E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_1-1669489621036.png" alt="Tom_1-1669489621036.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;And then roll it back up into a single observation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set want;
  by account_num product_id;
  retain status_code flag1-flag2;
  array _flag $1 flag1-flag2 ;
  length status_code $8 ;
  if first.product_id then call missing(of status_code _flag[*]);
  status_code=coalescec(status_code,r_code);
  _flag[order]=flag;
  if last.product_id;
  drop flag r_code order;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_2-1669489885150.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77735iBB4961B983812C78/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_2-1669489885150.png" alt="Tom_2-1669489885150.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This can easily be extended from TWO flag/order value to 50.&amp;nbsp; And no macros (or macro variables) are required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2022 19:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-this-problem/m-p/846432#M334618</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-26T19:13:56Z</dc:date>
    </item>
  </channel>
</rss>

