<?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: merging by priority in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/merging-by-priority/m-p/721984#M223814</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117414"&gt;@chinna0369&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have below data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input id;
datalines;
1287 
1805 
1881 
1881 
;
run;

data have2;
input id;
datalines;
1287 
1805 
1805 
1805 
1881 
1892 
1892 
1892 
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want records, below are the conditions:&lt;/P&gt;
&lt;P&gt;1. if have1 and have2 has same id then I want those records from have1.&lt;/P&gt;
&lt;P&gt;2. if have1 has the id and have2 doesn't have it then we want it.&lt;/P&gt;
&lt;P&gt;3. if have1 doesn't have the id and have2 has it then we want those records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input id;
datalines;
1287
1805
1881
1881
1892
1892
1892
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Adi&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I am having a very hard time telling what you want and whether you want 1, 2 or 3 data sets.&lt;/P&gt;
&lt;P&gt;Your current list of requirements basically says that you want everything, at least given the limited data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This creates 3 datasets, each matching a different one of your requirements. Not: you did not provide data that has any records for the second requirement.&lt;/P&gt;
&lt;PRE&gt;proc sort data=have1;
   by id;
run;

proc sort data=have2;
  by id;
run;

data want1
     want2
     want3
;
   merge have1 (in=in1)
         have2 (in=in2)
   ;&lt;BR /&gt;   by id;
   if in1 and in2 then output want1;
   if in1 and not in2 then output want2;
   if not in1 and in2 then output want3;
run;&lt;/PRE&gt;
&lt;P&gt;The IN= option creates a temporary variable that indicates whether the current record has a contribution from the given data set. This is a 1/0, i.e. true/false value, so can be used to perform conditional actions based on the status of the variable(s).&lt;/P&gt;</description>
    <pubDate>Thu, 25 Feb 2021 19:48:11 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-02-25T19:48:11Z</dc:date>
    <item>
      <title>merging by priority</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-by-priority/m-p/721958#M223807</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have below data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input id;
datalines;
1287 
1805 
1881 
1881 
;
run;

data have2;
input id;
datalines;
1287 
1805 
1805 
1805 
1881 
1892 
1892 
1892 
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want records, below are the conditions:&lt;/P&gt;&lt;P&gt;1. if have1 and have2 has same id then I want those records from have1.&lt;/P&gt;&lt;P&gt;2. if have1 has the id and have2 doesn't have it then we want it.&lt;/P&gt;&lt;P&gt;3. if have1 doesn't have the id and have2 has it then we want those records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input id;
datalines;
1287
1805
1881
1881
1892
1892
1892
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Adi&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 18:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-by-priority/m-p/721958#M223807</guid>
      <dc:creator>chinna0369</dc:creator>
      <dc:date>2021-02-25T18:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: merging by priority</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-by-priority/m-p/721969#M223808</link>
      <description>&lt;P&gt;Does this represent your actual data? Do you have only the ID variable in your data sets?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 19:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-by-priority/m-p/721969#M223808</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-25T19:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: merging by priority</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-by-priority/m-p/721984#M223814</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117414"&gt;@chinna0369&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have below data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input id;
datalines;
1287 
1805 
1881 
1881 
;
run;

data have2;
input id;
datalines;
1287 
1805 
1805 
1805 
1881 
1892 
1892 
1892 
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want records, below are the conditions:&lt;/P&gt;
&lt;P&gt;1. if have1 and have2 has same id then I want those records from have1.&lt;/P&gt;
&lt;P&gt;2. if have1 has the id and have2 doesn't have it then we want it.&lt;/P&gt;
&lt;P&gt;3. if have1 doesn't have the id and have2 has it then we want those records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input id;
datalines;
1287
1805
1881
1881
1892
1892
1892
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Adi&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I am having a very hard time telling what you want and whether you want 1, 2 or 3 data sets.&lt;/P&gt;
&lt;P&gt;Your current list of requirements basically says that you want everything, at least given the limited data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This creates 3 datasets, each matching a different one of your requirements. Not: you did not provide data that has any records for the second requirement.&lt;/P&gt;
&lt;PRE&gt;proc sort data=have1;
   by id;
run;

proc sort data=have2;
  by id;
run;

data want1
     want2
     want3
;
   merge have1 (in=in1)
         have2 (in=in2)
   ;&lt;BR /&gt;   by id;
   if in1 and in2 then output want1;
   if in1 and not in2 then output want2;
   if not in1 and in2 then output want3;
run;&lt;/PRE&gt;
&lt;P&gt;The IN= option creates a temporary variable that indicates whether the current record has a contribution from the given data set. This is a 1/0, i.e. true/false value, so can be used to perform conditional actions based on the status of the variable(s).&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 19:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-by-priority/m-p/721984#M223814</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-25T19:48:11Z</dc:date>
    </item>
  </channel>
</rss>

