<?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: Use merge to find different values for common variable in two data sets in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/421221#M12935</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data sheet1;
input id weight1;
datalines;
1 33
2 44
3 55
4 66
5 77
;
run;

Data sheet2;
input id weight2;
datalines;
1 11
2 44
3 55
4 66
5 88
; 
run; 
proc sort data=sheet1;by id;
proc sort data=sheet2;by id;
run;

data merge_12;
merge sheet1 sheet2;by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 14 Dec 2017 15:54:23 GMT</pubDate>
    <dc:creator>rvsidhu035</dc:creator>
    <dc:date>2017-12-14T15:54:23Z</dc:date>
    <item>
      <title>Use merge to find different values for common variable in two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418342#M12778</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have this problem (using sas universtiy):&lt;/P&gt;&lt;P&gt;I am supposed to merge datasets that have two common variables (id and weight) and look for values that are different for one variable (weight).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Say:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data sheet1;
input id weight1;
datalines;
1 33
2 44
3 55
4 66
5 77
;
run;

Data sheet2;
input id weight2;
datalines;
1 11
2 44
3 55
4 66
5 88
;&amp;nbsp;
run;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;To identify observations 1 and 5 I would run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data differences;
merge sheet1 sheet2;
by id;
run;


Data differences;
set differences;
where weight1 ne weight2;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Provided&amp;nbsp; they're propperly sorted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I am supposed to run this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data differences;
merge sheet1 sheet2 (in =a);
by id weight;
if a;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I just don't understand how that's supposed to work. The way I understand it is that the datasets are merged by id and weight for all observations in a and&amp;nbsp;&amp;nbsp;overwriting values that are different with those from sheet2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe I'm not thinking of the right data structure. My supervisor tried to explain it to me, saying that the merge statement would create missings for values that aren't equal on both datasets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone fill me in? Thanks's in advance!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 01:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418342#M12778</guid>
      <dc:creator>Iona</dc:creator>
      <dc:date>2017-12-05T01:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Use merge to find different values for common variable in two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418350#M12779</link>
      <description>&lt;P&gt;Since you don't have a variable called weight, that code wouldn't run. Your supervisor may have been suggesting something like:&lt;/P&gt;
&lt;PRE&gt;data differences;
  merge sheet1 (rename=(weight1=weight) in=a) 
        sheet2 (rename=(weight2=weight) in=b);
  by id weight;
  if a and not b;
run; 
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 02:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418350#M12779</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-12-05T02:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Use merge to find different values for common variable in two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418354#M12780</link>
      <description>&lt;BR /&gt;Hi Art,&lt;BR /&gt;&lt;BR /&gt;thanks for your reply! In my version the data sets would have weight1 and weight 2, and in the supervisor's version only weight. Sorry for the confusion! I was just concentrating on the merge question and on how a merge can return different values, only.&lt;BR /&gt;&lt;BR /&gt;I was wondering about the if a and not b statement, too, but she uses only "if a", like in the example. It's a direct copy of what she did.</description>
      <pubDate>Tue, 05 Dec 2017 02:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418354#M12780</guid>
      <dc:creator>Iona</dc:creator>
      <dc:date>2017-12-05T02:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Use merge to find different values for common variable in two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418356#M12781</link>
      <description>&lt;P&gt;If you have other variables exclusively in sheet1 (say x1 y1), and you performed the merge as you presented, then &lt;EM&gt;&lt;STRONG&gt;for cases where the BY-variables ID and WEIGHT appear only in sheet2, you would indeed have missing values assigned to X1 and Y1 in the output&lt;/STRONG&gt;&lt;/EM&gt;.&amp;nbsp; For other cases, in which ID and WEIGHT appear in both sheets,&amp;nbsp;you would get the original values found in&amp;nbsp;sheet1.&amp;nbsp; Perhaps that is what your supervisor is referring to.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 02:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418356#M12781</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-12-05T02:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Use merge to find different values for common variable in two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418362#M12784</link>
      <description>&lt;P&gt;Your question and the 'supervisor' answer don't appear to align. So either you're misunderstanding the question or her answer.&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/116825"&gt;@Iona&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have this problem (using sas universtiy):&lt;/P&gt;
&lt;P&gt;I am supposed to merge datasets that have two common variables (id and weight) and look for values that are different for one variable (weight).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data sheet1;
input id weight1;
datalines;
1 33
2 44
3 55
4 66
5 77
;
run;

Data sheet2;
input id weight2;
datalines;
1 11
2 44
3 55
4 66
5 88
;&amp;nbsp;
run;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To identify observations 1 and 5 I would run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data differences;
merge sheet1 sheet2;
by id;
run;


Data differences;
set differences;
where weight1 ne weight2;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Provided&amp;nbsp; they're propperly sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I am supposed to run this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data differences;
merge sheet1 sheet2 (in =a);
by id weight;
if a;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And I just don't understand how that's supposed to work. The way I understand it is that the datasets are merged by id and weight for all observations in a and&amp;nbsp;&amp;nbsp;overwriting values that are different with those from sheet2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe I'm not thinking of the right data structure. My supervisor tried to explain it to me, saying that the merge statement would create missings for values that aren't equal on both datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone fill me in? Thanks's in advance!&amp;nbsp;&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 03:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418362#M12784</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-05T03:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: Use merge to find different values for common variable in two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418626#M12797</link>
      <description>&lt;P&gt;Thanks for your replies!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I'm halfway understanding what she wants me to do. So we have two data sets and three variables. Id has equal values in both datasets, but ref_var and value_A (value_B respectively) are different. What she wants me to do is to merge datasets A and B in a way that creates missings vor value_A and value_B where they are different.&lt;/P&gt;&lt;P&gt;The given datasets:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
input id ref_var value_A;
datalines;
1 1 1 
1 2 2
2 3 3
3 1 1 
; 
run;

data B;
input id ref_var value_B;
datalines;
1 1 1
1 3 3
2 1 1
3 1 1
; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I should have in the end:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data desired;
input id ref_var value_A value_B;
datalines;
1 1 1 1
1 2 2 .
1 3 . 3
2 1 . 1
2 3 3 .
3 1 1 1
; 
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this is the template that she gave me but I must be doing it wrong as I am only getting the missings vor value_B but not for value_A.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data differences;
merge A (in =a) B;
by id ref_var;
if a;
if ref_var eq . then delete;
if value_B eq . then output;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&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="result.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17039i1AC005A2F5E68A00/image-size/large?v=v2&amp;amp;px=999" role="button" title="result.PNG" alt="result.PNG" /&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;Adding "if value_A eq . then output" doesn't help or even change the output.&amp;nbsp; Can someone spot my mistake?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 22:30:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418626#M12797</guid>
      <dc:creator>Iona</dc:creator>
      <dc:date>2017-12-05T22:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: Use merge to find different values for common variable in two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418631#M12798</link>
      <description>&lt;P&gt;Given what you now want, your code is far too complex. To get the desired result you only need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data desired;
  merge A B;
  by id ref_var;
run; 
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 22:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418631#M12798</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-12-05T22:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Use merge to find different values for common variable in two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418972#M12831</link>
      <description>&lt;P&gt;That did it, thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2017 22:07:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/418972#M12831</guid>
      <dc:creator>Iona</dc:creator>
      <dc:date>2017-12-06T22:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: Use merge to find different values for common variable in two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/419913#M12867</link>
      <description>Data sheet1; input id weight1; datalines; 1 33 2 44 3 55 4 66 5 77 ; run; Data sheet2; input id weight2; datalines; 1 11 2 44 3 55 4 66 5 88 ; run; proc sort data=sheet1;by id; proc sort data=sheet2; by id; data merge23; merge sheet1 sheet2;by id; run;</description>
      <pubDate>Sun, 10 Dec 2017 12:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/419913#M12867</guid>
      <dc:creator>rvsidhu035</dc:creator>
      <dc:date>2017-12-10T12:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Use merge to find different values for common variable in two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/421221#M12935</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data sheet1;
input id weight1;
datalines;
1 33
2 44
3 55
4 66
5 77
;
run;

Data sheet2;
input id weight2;
datalines;
1 11
2 44
3 55
4 66
5 88
; 
run; 
proc sort data=sheet1;by id;
proc sort data=sheet2;by id;
run;

data merge_12;
merge sheet1 sheet2;by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Dec 2017 15:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Use-merge-to-find-different-values-for-common-variable-in-two/m-p/421221#M12935</guid>
      <dc:creator>rvsidhu035</dc:creator>
      <dc:date>2017-12-14T15:54:23Z</dc:date>
    </item>
  </channel>
</rss>

