<?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: Iterate over two datasets and update the flag in Developers</title>
    <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846208#M6237</link>
    <description>&lt;P&gt;In which case, try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Dataset1;
input Group_Id Account_Number Reject_code $;
infile datalines missover;
datalines;
1 8561234 
1 8881246 
2 9412381 
4 8718912 
;

data Dataset2;
input Group_Id Account_Number Status_Code $;
datalines;
1 8561234  c01 
1 8881246  d85 
2 48981211 e48 
;

data want;

   if _N_ = 1 then do;
      dcl hash h(dataset : 'Dataset2(rename = Status_Code = Reject_code)');
      h.definekey('Group_Id');
      h.definedata('Reject_code');
      h.definedone();
   end; 

   set Dataset1;

   _N_ = h.find();
   
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 24 Nov 2022 18:37:58 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-11-24T18:37:58Z</dc:date>
    <item>
      <title>Iterate over two datasets and update the flag</title>
      <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846202#M6233</link>
      <description>&lt;P&gt;Hello ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 different datasets, listed below. I have requirement - for every account in dataset1 it should iterate through each row in dataset2 and check if dataset1.groupid=dataset2.groupid and if it matches update&amp;nbsp; dataset2.status_code value in dataset1.reject_code. Here only the clause reject_code should be updated with first matching row of dataset2 and then it can break the dataset2 loop and skip to next account in dataset1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset1&lt;/P&gt;&lt;P&gt;Group_Id Account_Number&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;Reject_code&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8561234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&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;8881246&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9412381&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8718912&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset2&lt;/P&gt;&lt;P&gt;Group_Id Reject_Code Status_Code&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;8561234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c01&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8881246&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; d85&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;48981211&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;e48&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the pseudo code am thinking of but couldn't do working implementation in sas.&lt;/P&gt;&lt;P&gt;loopcnt is no of rows of dataset1 and loopcntr is no of rows in dataset2. Please ignore syntax mistakes and treat it as pseudo code.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Can you please advise on how to implement this as am stuck with it ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let %i=1;&lt;/P&gt;&lt;P&gt;let %j=1;&lt;/P&gt;&lt;P&gt;%do %until (&amp;amp;i &amp;lt; &amp;amp;loopcnt);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %do %until (&amp;amp;j &amp;lt;&amp;amp;loopcntr)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if dataset1[i].group_id=dataset2[j].group_id&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;then update dataset1.reject_code=dataset.status_code.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%end&lt;/P&gt;&lt;P&gt;%end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 18:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846202#M6233</guid>
      <dc:creator>sasuser_01</dc:creator>
      <dc:date>2022-11-24T18:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate over two datasets and update the flag</title>
      <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846204#M6234</link>
      <description>&lt;P&gt;If those are the input data sets, what is the expected output? Since you mention that only the first one should be updated, please include a few cases where a record may not be updated or there are multiple records to consider and only the first should be chosen.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&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;
&lt;P&gt;Hello ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 2 different datasets, listed below. I have requirement - for every account in dataset1 it should iterate through each row in dataset2 and check if dataset1.groupid=dataset2.groupid and if it matches update&amp;nbsp; dataset2.status_code value in dataset1.reject_code. Here only the clause reject_code should be updated with &lt;STRONG&gt;first matching row of dataset2&lt;/STRONG&gt; and then it can break the dataset2 loop and skip to next account in dataset1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dataset1&lt;/P&gt;
&lt;P&gt;Group_Id Account_Number&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;Reject_code&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8561234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&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;8881246&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9412381&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8718912&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dataset2&lt;/P&gt;
&lt;P&gt;Group_Id Reject_Code Status_Code&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;8561234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c01&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8881246&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; d85&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;48981211&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;e48&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the pseudo code am thinking of but couldn't do working implementation in sas.&lt;/P&gt;
&lt;P&gt;loopcnt is no of rows of dataset1 and loopcntr is no of rows in dataset2. Please ignore syntax mistakes and treat it as pseudo code.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Can you please advise on how to implement this as am stuck with it ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;let %i=1;&lt;/P&gt;
&lt;P&gt;let %j=1;&lt;/P&gt;
&lt;P&gt;%do %until (&amp;amp;i &amp;lt; &amp;amp;loopcnt);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %do %until (&amp;amp;j &amp;lt;&amp;amp;loopcntr)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if dataset1[i].group_id=dataset2[j].group_id&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;then update dataset1.reject_code=dataset.status_code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%end&lt;/P&gt;
&lt;P&gt;%end&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 18:16:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846204#M6234</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-24T18:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate over two datasets and update the flag</title>
      <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846205#M6235</link>
      <description>&lt;P&gt;If I understand your requirement correctly, your desired result looks like this, right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Group_Id Account_Number  Reject_code
1        8561234         c01
1        8881246         c01
2        9412381         e48
4        8718912          &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Nov 2022 18:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846205#M6235</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-24T18:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate over two datasets and update the flag</title>
      <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846206#M6236</link>
      <description>&lt;P&gt;Since it looks like you are working with actual data in datasets this does not look like something where macro code would be of any value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is wrong with simply merging the two datasets by the common key variable?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
  input Group_Id Account_Number;
cards;
1 8561234
1 8881246
2 9412381
4 8718912
;

data two;
  input Group_Id Account_Number Status_Code $ ;
cards;
1 8561234  c01
1 8881246  d85
2 48981211 e48
;

data want;
  merge one two;
  by group_id account_number;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;                   Account_    Status_
Obs    Group_Id     Number      Code

 1         1        8561234      c01
 2         1        8881246      d85
 3         2        9412381
 4         2       48981211      e48
 5         4        8718912

&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Nov 2022 18:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846206#M6236</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-24T18:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate over two datasets and update the flag</title>
      <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846208#M6237</link>
      <description>&lt;P&gt;In which case, try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Dataset1;
input Group_Id Account_Number Reject_code $;
infile datalines missover;
datalines;
1 8561234 
1 8881246 
2 9412381 
4 8718912 
;

data Dataset2;
input Group_Id Account_Number Status_Code $;
datalines;
1 8561234  c01 
1 8881246  d85 
2 48981211 e48 
;

data want;

   if _N_ = 1 then do;
      dcl hash h(dataset : 'Dataset2(rename = Status_Code = Reject_code)');
      h.definekey('Group_Id');
      h.definedata('Reject_code');
      h.definedone();
   end; 

   set Dataset1;

   _N_ = h.find();
   
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Nov 2022 18:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846208#M6237</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-24T18:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate over two datasets and update the flag</title>
      <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846209#M6238</link>
      <description>&lt;P&gt;&lt;BR /&gt;Yes that's correct. Here is how output dataset , dataset1 &amp;amp; datset2 looks like . Please let me know&lt;BR /&gt;&lt;BR /&gt;output dataset:&lt;BR /&gt;Group_Id Account_Number Reject_Code&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8561234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c01&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8881246&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c01&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9412381&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e48&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8718912&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; g9&lt;BR /&gt;&lt;BR /&gt;Dataset1&lt;BR /&gt;Group_Id Account_Number&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8561234&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8881246&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9412381&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8718912&lt;BR /&gt;&lt;BR /&gt;Dataset2:&lt;BR /&gt;Group_Id Reject_Code Status_Code&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reject1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c01&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reject2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;d85&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reject3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;e48&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reject4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;f12&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reject5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;g9&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 18:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846209#M6238</guid>
      <dc:creator>sasuser_01</dc:creator>
      <dc:date>2022-11-24T18:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate over two datasets and update the flag</title>
      <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846211#M6239</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Issue with merging is :&amp;nbsp;&lt;/P&gt;&lt;P&gt;For every account number in dataset1 it should iterate through dataset2 and get the first matching status_code&amp;nbsp; ( based on dataset1.group_id =dataset2.group_id) . I have updated how output dataset, dataset1 and dataset2 should look like in other response. You can refer to that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By merging, it doesn't check first matching condition and it just merges based on clause of groupid and account number. Also we want every account_number in datset1 even though corresponding group id is not present in dataset2.&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;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 19:06:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846211#M6239</guid>
      <dc:creator>sasuser_01</dc:creator>
      <dc:date>2022-11-24T19:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate over two datasets and update the flag</title>
      <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846214#M6240</link>
      <description>&lt;P&gt;Did you try my code above? Also, the data you posted just not is not the same as the original data from your post.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 19:34:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846214#M6240</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-24T19:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate over two datasets and update the flag</title>
      <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846215#M6241</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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Issue with merging is :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For every account number in dataset1 it should iterate through dataset2 and get the first matching status_code&amp;nbsp; ( based on dataset1.group_id =dataset2.group_id) . I have updated how output dataset, dataset1 and dataset2 should look like in other response. You can refer to that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By merging, it doesn't check first matching condition and it just merges based on clause of groupid and account number. Also we want every account_number in datset1 even though corresponding group id is not present in dataset2.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That does not make any sense.&amp;nbsp; Every observation in dataset1 will obviously be included unless you add something to remove them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show some data that actually reflect the issues you are having with merging.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to match by just GROUP_ID then do that.&amp;nbsp; If you only want the first match then do that.&lt;/P&gt;
&lt;P&gt;So this step will take the first value of STATUS_CODE and store it into the variable WANT.&amp;nbsp; It will output every distinct value of GROUP_ID that appears in the ACCOUNT dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge account(in=in1) codes(in=in2);
  by group_id;
  retain found ;
  if first.group_id then found=0;
  if in2 and not found then do;
    found=1;
    want = status_code;
    retain want;
  end;
  if last.group_id and in1;
run;
  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 19:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846215#M6241</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-24T19:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate over two datasets and update the flag</title>
      <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846216#M6242</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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Issue with merging is :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For every account number in dataset1 it should iterate through dataset2 and get the first matching status_code&amp;nbsp; ( based on dataset1.group_id =dataset2.group_id) . I have updated how output dataset, dataset1 and dataset2 should look like in other response. You can refer to that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;By merging, it doesn't check first matching condition and it just merges based on clause of groupid and account number. Also we want every account_number in datset1 even though corresponding group id is not present in dataset2.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can you include an example of that scenario in your sample data&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 19:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846216#M6242</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-24T19:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate over two datasets and update the flag</title>
      <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846218#M6243</link>
      <description>&lt;P&gt;Merge works fine for that example.&lt;/P&gt;
&lt;P&gt;First let's create some actual datasets from the listings you posted.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data expect;
  input Group_Id Account_Number Reject_Code $;
cards;
1 8561234 c01
1 8881246 c01
2 9412381 e48
4 8718912 g9
;

data accounts;
  input Group_Id Account_Number;
cards;
1 8561234
1 8881246
2 9412381
4 8718912
;

data codes ;
  input Group_Id Reject_Code $ Status_Code $;
cards;
1 reject1 c01
1 reject2 d85
2 reject3 e48
2 reject4 f12
4 reject5 g9
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And make sure they are sorted in the proper order.&amp;nbsp; I assume the REJECT_CODE variable is the ordering variable in the CODES dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=codes ;
  by group_id reject_code ;
run;

proc sort data=accounts;
  by group_id account_number;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now just merge them and keep track of the first value of STATUS_CODE.&amp;nbsp; Since the variable name in your expected result is already being used in the CODES dataset let's just use the name WANT in the data step.&amp;nbsp; We can rename the two variables when it is written out.&amp;nbsp; You can drop the REJECT_CODE and STATUS_CODE variables read from the CODES dataset if you want to get expected output exactly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge accounts(in=in1) codes(in=in2);
  by group_id ;
  retain found want ;
  if first.group_id then found=0;
  if in2 and not found then do;
    found=1;
    want=status_code ;
  end;
  if in1 then output;
  in1=0;
  rename reject_code = reject_codeB want=reject_code;
  drop found;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;                   Account_    reject_    Status_    reject_
Obs    Group_Id     Number      codeB      Code       code

 1         1        8561234    reject1      c01        c01
 2         1        8881246    reject2      d85        c01
 3         2        9412381    reject3      e48        e48
 4         4        8718912    reject5      g9         g9
&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Of course it would be even easier to just eliminate the unwanted codes before the merge&lt;/STRONG&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data codes2;
  set codes;
  by group_id;
  if first.group_id;
run;

data want;
  merge accounts(in=in1) codes2;
  by group_id;
  if in1;
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Again if you want you can DROP the REJECT_CODE variable and rename the STATUS_CODE variable to REJECT_CODE.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 20:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846218#M6243</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-24T20:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate over two datasets and update the flag</title>
      <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846226#M6244</link>
      <description>See my example on my tips and tricks page: &lt;A href="https://github.com/savian-net/SasTipsTricks#use-a-dataset-as-a-lookup-in-another-dataset" target="_blank"&gt;https://github.com/savian-net/SasTipsTricks#use-a-dataset-as-a-lookup-in-another-dataset&lt;/A&gt;</description>
      <pubDate>Thu, 24 Nov 2022 21:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/846226#M6244</guid>
      <dc:creator>AlanC</dc:creator>
      <dc:date>2022-11-24T21:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate over two datasets and update the flag</title>
      <link>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/852190#M6256</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437292"&gt;@sasuser_01&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;This thread has gone a while with no activity. Were you able to attempt the solutions provided from other community members? Are you able to provide the requested data?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Joe&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 20:26:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Iterate-over-two-datasets-and-update-the-flag/m-p/852190#M6256</guid>
      <dc:creator>joeFurbee</dc:creator>
      <dc:date>2023-01-04T20:26:29Z</dc:date>
    </item>
  </channel>
</rss>

