<?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: Merge two data sets by id when the two variables have equal values in different rows in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418125#M12759</link>
    <description>&lt;P&gt;Thanks draycut,&lt;BR /&gt;&lt;BR /&gt;how I could please keep the other variables in both data sets when I'm using proc sql&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;for example if I have age in the first data set and weight in the second data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Dec 2017 12:19:06 GMT</pubDate>
    <dc:creator>elias_2020</dc:creator>
    <dc:date>2017-12-04T12:19:06Z</dc:date>
    <item>
      <title>Merge two data sets by id when the two variables have equal values in different rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418112#M12757</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;could you suggest for me how I could merge the two data sets by id, if I have two variables have equal values but in different rows.&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ONE; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;INPUT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ID VAR1 $; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;CARDS&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 C&lt;/P&gt;&lt;P&gt;1 A&lt;/P&gt;&lt;P&gt;1 D&lt;/P&gt;&lt;P&gt;2 A&lt;/P&gt;&lt;P&gt;2 B&lt;/P&gt;&lt;P&gt;3 C&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; TWO; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;INPUT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ID VAR2 $; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;CARDS&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 E&lt;/P&gt;&lt;P&gt;1 C&lt;/P&gt;&lt;P&gt;1 D&lt;/P&gt;&lt;P&gt;1 A&lt;/P&gt;&lt;P&gt;2 A&lt;/P&gt;&lt;P&gt;2 B&lt;/P&gt;&lt;P&gt;2 D&lt;/P&gt;&lt;P&gt;3 A&lt;/P&gt;&lt;P&gt;3 C&lt;/P&gt;&lt;P&gt;4 F&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*The correct results should be as belwo&lt;/P&gt;&lt;P&gt;ID VAR1 VAR2&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; &amp;nbsp;C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;A&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; D&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;D&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;A&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;B&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;C&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*I tried the folloiwng code, but it didn't gave me the correct answer*/&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;merge&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; one(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=a) two(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=b);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ID;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; var1=var2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 11:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418112#M12757</guid>
      <dc:creator>elias_2020</dc:creator>
      <dc:date>2017-12-04T11:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two data sets by id when the two variables have equal values in different rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418118#M12758</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table want as
	select ONE.ID, VAR1, VAR2
	from ONE left join TWO
	on ONE.ID=TWO.ID and ONE.VAR1=TWO.VAR2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Dec 2017 11:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418118#M12758</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-12-04T11:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two data sets by id when the two variables have equal values in different rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418125#M12759</link>
      <description>&lt;P&gt;Thanks draycut,&lt;BR /&gt;&lt;BR /&gt;how I could please keep the other variables in both data sets when I'm using proc sql&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;for example if I have age in the first data set and weight in the second data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 12:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418125#M12759</guid>
      <dc:creator>elias_2020</dc:creator>
      <dc:date>2017-12-04T12:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two data sets by id when the two variables have equal values in different rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418127#M12760</link>
      <description>&lt;P&gt;What other variables? Please be more specific.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 12:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418127#M12760</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-12-04T12:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two data sets by id when the two variables have equal values in different rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418128#M12761</link>
      <description>&lt;P&gt;Merge on both variables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input id var1 $;
cards;
1 C
1 A
1 D
2 A
2 B
3 C
;
run;

data two;
input id var2 $;
cards;
1 E
1 C
1 D
1 A
2 A
2 B
2 D
3 A
3 C
4 F
;
run;


proc sort data=one;
by id var1;
run;

proc sort data=two;
by id var2;
run;

data want;
merge
  one (in=a)
  two (in=b rename=(var2=var1))
;
by id var1;
if a and b;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;id    var1

 1     A  
 1     C  
 1     D  
 2     A  
 2     B  
 3     C  
&lt;/PRE&gt;
&lt;P&gt;Since var2 would be equal to var1 anyways, there's no need to keep it.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 12:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418128#M12761</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-12-04T12:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two data sets by id when the two variables have equal values in different rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418129#M12762</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA ONE; 
  INPUT ID VAR1 $  height; 
CARDS; 
1 C  167 
1 A  168
1 D  168
2 A  172
2 B  174
3 C  171
; 
RUN; 


DATA TWO; 
  INPUT ID VAR2 $  age; 
CARDS; 
1 E  21
1 C  22  
1 D  24
1 A  25
2 A  20
2 B  22
2 D  28
3 A  24
3 C  26
4 F  27
; 
RUN; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*The correct results should be as belwo&lt;/P&gt;&lt;P&gt;ID VAR1 VAR2 height&amp;nbsp;&amp;nbsp; age&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;C&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;167&amp;nbsp;&amp;nbsp; &amp;nbsp; 22&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 168&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;24&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;D&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;D&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 168&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;24&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;172&amp;nbsp;&amp;nbsp; &amp;nbsp;20&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 174&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;171&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;26&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 12:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418129#M12762</guid>
      <dc:creator>elias_2020</dc:creator>
      <dc:date>2017-12-04T12:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two data sets by id when the two variables have equal values in different rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418131#M12763</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@oalbalawi wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA ONE; 
  INPUT ID VAR1 $  height; 
CARDS; 
1 C  167 
1 A  165
1 D  168
2 A  172
2 B  174
3 C  171
; 
RUN; 


DATA TWO; 
  INPUT ID VAR2 $  age; 
CARDS; 
1 E  21
1 C  22  
1 D  24
1 A  25
2 A  20
2 B  22
2 D  28
3 A  24
3 C  26
4 F  27
; 
RUN; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*The correct results should be as belwo&lt;/P&gt;
&lt;P&gt;ID VAR1 VAR2 hight&amp;nbsp;&amp;nbsp; age&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;C&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;167&amp;nbsp;&amp;nbsp; &amp;nbsp; 22&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 168&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;24&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;D&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;D&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 169&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;24&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;172&amp;nbsp;&amp;nbsp; &amp;nbsp;20&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 174&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;/P&gt;
&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;171&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;26&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your result does not match your data. There's no height of 169 anywhere, and id = 1 var1 = A has an age of 25.&lt;/P&gt;
&lt;P&gt;Apart from that, my code works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input id var1 $ age;
cards;
1 C 167
1 A 165
1 D 168
2 A 172
2 B 174
3 C 171
;
run;

data two;
input id var2 $ height;
cards;
1 E 21
1 C 22
1 D 24
1 A 25
2 A 20
2 B 22
2 D 28
3 A 24
3 C 26
4 F 27
;
run;


proc sort data=one;
by id var1;
run;

proc sort data=two;
by id var2;
run;

data want;
merge
  one (in=a)
  two (in=b rename=(var2=var1))
;
by id var1;
if a and b;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;id    var1    age    height

 1     A      165      25  
 1     C      167      22  
 1     D      168      24  
 2     A      172      20  
 2     B      174      22  
 3     C      171      26  
&lt;/PRE&gt;
&lt;P&gt;Only the order changes, because of the sort. If you want to preserve the orignal order, you need to create a helper variable on which to re-sort after the merge.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 12:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418131#M12763</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-12-04T12:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two data sets by id when the two variables have equal values in different rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418134#M12764</link>
      <description>&lt;P&gt;Thanks KurtBremser.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, it was error typing in record the height of id=1 and the age id=1 &amp;amp; var1=A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please show me any example of how I can keep the order of height and age &amp;nbsp;because&amp;nbsp; when I sort the data the age of each id will not be in the correct order.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 12:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418134#M12764</guid>
      <dc:creator>elias_2020</dc:creator>
      <dc:date>2017-12-04T12:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two data sets by id when the two variables have equal values in different rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418136#M12765</link>
      <description>&lt;P&gt;Add a variable in table one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input id var1 $ age;
keepsort = _n_;
cards;
1 C 167
1 A 165
1 D 168
2 A 172
2 B 174
3 C 171
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;At the end, sort by that, and drop if you don't need it any longer:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=want;
by keepsort;
run;

proc print data=want (drop=keepsort) noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Adapted result:&lt;/P&gt;
&lt;PRE&gt;id    var1    age    height

 1     C      167      22  
 1     A      165      25  
 1     D      168      24  
 2     A      172      20  
 2     B      174      22  
 3     C      171      26  
&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Dec 2017 12:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418136#M12765</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-12-04T12:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two data sets by id when the two variables have equal values in different rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418146#M12766</link>
      <description>&lt;P&gt;Thanks KurtBremser.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 13:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Merge-two-data-sets-by-id-when-the-two-variables-have-equal/m-p/418146#M12766</guid>
      <dc:creator>elias_2020</dc:creator>
      <dc:date>2017-12-04T13:41:04Z</dc:date>
    </item>
  </channel>
</rss>

