<?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: Search one data set to another data set and create new data set based on operation peformed in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Search-one-data-set-to-another-data-set-and-create-new-data-set/m-p/434007#M28044</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA product_test;
INFILE DATALINES DELIMITER=',' DSD;
INPUT new_prod_id $ new_store_id $ old_prod_id $ old_store_id $;

DATALINES;
11,1,10,10
13,2,31,9
12,3,21,8
14,4,41,7
16,5,63,6
RUN;

 

 

DATA purchase;
INFILE DATALINES DELIMITER=',' DSD;
INPUT id $ prod_id $ store_id $ quantity value;

DATALINES;
1,10,10,10,100
2,31,10,4,10
3,31,9,3,100
4,31,9,12,100
5,21,8,6,100
6,63,6,5,100
7,21,8,3,100
8,41,7,2,100
9,21,8,1,100
10,63,9,5,100
RUN;


proc sort data=product_test out=_product_test(rename=(old_prod_id=prod_id old_store_id=store_id)) ;
by old_store_id old_prod_id ;
run;

proc sort data=purchase out=_purchase ;
by store_id prod_id ;
run;

data want;
merge _product_test(in=a) _purchase(in=b);
by store_id prod_id ;
if a and b then do;
if first.prod_id and first.store_id then _quant=0;
_quant+quantity;
prod_id=new_prod_id; store_id=new_store_id;
end;
if  a and b and last.prod_id;
drop new: id quantity;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 04 Feb 2018 20:23:47 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-02-04T20:23:47Z</dc:date>
    <item>
      <title>Search one data set to another data set and create new data set based on operation peformed</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Search-one-data-set-to-another-data-set-and-create-new-data-set/m-p/433979#M28043</link>
      <description>&lt;P&gt;Hi friends,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I have two data set and i want to search value of variables of each observation of data set to another data set and performed certain operation and create new data set or modified the current data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; i have tried using merge but i failed and again i tried macro but it did not work as well. please help me to generate the required output. i have very huge data set in order to explain the question i have created very small data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All required data set is following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;product_test&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="product_test.jpg" style="width: 502px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18312iA689AE6EDFAD80AD/image-size/large?v=v2&amp;amp;px=999" role="button" title="product_test.jpg" alt="product_test.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;purchase&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="purchase.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18313i34A8D61E71D5BA59/image-size/large?v=v2&amp;amp;px=999" role="button" title="purchase.jpg" alt="purchase.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;There are 2 data set product_test and purchase. i have to search &lt;STRONG&gt;old_prod_id&lt;/STRONG&gt; and &lt;STRONG&gt;old_store_id&lt;/STRONG&gt; of &lt;STRONG&gt;product_test&amp;nbsp;&lt;/STRONG&gt; data set with &lt;STRONG&gt;prod_id&lt;/STRONG&gt; and &lt;STRONG&gt;store_id&lt;/STRONG&gt; of &lt;STRONG&gt;purchase&lt;/STRONG&gt; data set where match found replace &lt;STRONG&gt;prod_id&lt;/STRONG&gt; and &lt;STRONG&gt;store_id&lt;/STRONG&gt; with &lt;STRONG&gt;new_prod_id&lt;/STRONG&gt; and &lt;STRONG&gt;new_store_id&lt;/STRONG&gt;&amp;nbsp;if it occur more than once then merge the observation and create new data set or modified purchase data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="final_output.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18314i042A40910F1D316E/image-size/large?v=v2&amp;amp;px=999" role="button" title="final_output.jpg" alt="final_output.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA product_test;&lt;BR /&gt;INFILE DATALINES DELIMITER=',' DSD;&lt;BR /&gt;INPUT new_prod_id $ new_store_id $ old_prod_id $ old_store_id $;&lt;/P&gt;&lt;P&gt;DATALINES;&lt;BR /&gt;11,1,10,10&lt;BR /&gt;13,2,31,9&lt;BR /&gt;12,3,21,8&lt;BR /&gt;14,4,41,7&lt;BR /&gt;16,5,63,6&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA purchase;&lt;BR /&gt;INFILE DATALINES DELIMITER=',' DSD;&lt;BR /&gt;INPUT id $ prod_id $ store_id $ quantity value;&lt;/P&gt;&lt;P&gt;DATALINES;&lt;BR /&gt;1,10,10,10,100&lt;BR /&gt;2,31,10,4,10&lt;BR /&gt;3,31,9,3,100&lt;BR /&gt;4,31,9,12,100&lt;BR /&gt;5,21,8,6,100&lt;BR /&gt;6,63,6,5,100&lt;BR /&gt;7,21,8,3,100&lt;BR /&gt;8,41,7,2,100&lt;BR /&gt;9,21,8,1,100&lt;BR /&gt;10,63,9,5,100&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2018 16:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Search-one-data-set-to-another-data-set-and-create-new-data-set/m-p/433979#M28043</guid>
      <dc:creator>ramanandyadav</dc:creator>
      <dc:date>2018-02-04T16:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Search one data set to another data set and create new data set based on operation peformed</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Search-one-data-set-to-another-data-set-and-create-new-data-set/m-p/434007#M28044</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA product_test;
INFILE DATALINES DELIMITER=',' DSD;
INPUT new_prod_id $ new_store_id $ old_prod_id $ old_store_id $;

DATALINES;
11,1,10,10
13,2,31,9
12,3,21,8
14,4,41,7
16,5,63,6
RUN;

 

 

DATA purchase;
INFILE DATALINES DELIMITER=',' DSD;
INPUT id $ prod_id $ store_id $ quantity value;

DATALINES;
1,10,10,10,100
2,31,10,4,10
3,31,9,3,100
4,31,9,12,100
5,21,8,6,100
6,63,6,5,100
7,21,8,3,100
8,41,7,2,100
9,21,8,1,100
10,63,9,5,100
RUN;


proc sort data=product_test out=_product_test(rename=(old_prod_id=prod_id old_store_id=store_id)) ;
by old_store_id old_prod_id ;
run;

proc sort data=purchase out=_purchase ;
by store_id prod_id ;
run;

data want;
merge _product_test(in=a) _purchase(in=b);
by store_id prod_id ;
if a and b then do;
if first.prod_id and first.store_id then _quant=0;
_quant+quantity;
prod_id=new_prod_id; store_id=new_store_id;
end;
if  a and b and last.prod_id;
drop new: id quantity;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Feb 2018 20:23:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Search-one-data-set-to-another-data-set-and-create-new-data-set/m-p/434007#M28044</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-04T20:23:47Z</dc:date>
    </item>
  </channel>
</rss>

