<?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: It is possible work with two datasets with MERGE both with same structure / same variable names? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/It-is-possible-work-with-two-datasets-with-MERGE-both-with-same/m-p/332759#M74938</link>
    <description>&lt;P&gt;Using the example data that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;provided, something like the following would work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;libname lib 'c:\art';
data lib.one;
   input id $ x;
datalines;
a  13
b  14
c  15
;

data lib.two;
   input id $ x;
datalines;
b  23
c  24
d  25
;

data combined;
   merge
      lib.one (in=a keep=id x rename=(x=_x))
      lib.two (in=b)
   ;
   by id;
   if a and b;
   dif=x-_x;
run;

run;&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Feb 2017 18:43:02 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-02-14T18:43:02Z</dc:date>
    <item>
      <title>It is possible work with two datasets with MERGE both with same structure / same variable names?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/It-is-possible-work-with-two-datasets-with-MERGE-both-with-same/m-p/332752#M74933</link>
      <description>&lt;P&gt;I have 2 similar datasets by different date same structure / same variable names:&lt;/P&gt;&lt;P&gt;DS2016&lt;/P&gt;&lt;P&gt;DS2017&lt;/P&gt;&lt;P&gt;how can I compare or work with variables if i use a MERGE? some like...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NEW_DS;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;merge&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;lib.DS2016(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;IN&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=A)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New"&gt;lib.DS2017&lt;/FONT&gt;(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;IN&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=B);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ID;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;IF&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; A &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AND&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; B;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;*******************&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;IN THIS SPACE WORK WITH VARIABLES LIKE WITH PROC SQL:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;NEWVAR= &lt;FONT face="Courier New"&gt;DS2016.var1-DS2017.var1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;*******************&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I dont know how it works because I dont know how identify what variable is each for differente dataset&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 18:21:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/It-is-possible-work-with-two-datasets-with-MERGE-both-with-same/m-p/332752#M74933</guid>
      <dc:creator>Angel_Saenz</dc:creator>
      <dc:date>2017-02-14T18:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: It is possible work with two datasets with MERGE both with same structure / same variable names?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/It-is-possible-work-with-two-datasets-with-MERGE-both-with-same/m-p/332754#M74934</link>
      <description>&lt;P&gt;Do you want to know about how a merge statement works?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 18:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/It-is-possible-work-with-two-datasets-with-MERGE-both-with-same/m-p/332754#M74934</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-02-14T18:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: It is possible work with two datasets with MERGE both with same structure / same variable names?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/It-is-possible-work-with-two-datasets-with-MERGE-both-with-same/m-p/332755#M74935</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/107284"&gt;@Angel_Saenz&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have 2 similar datasets by different date same structure / same variable names:&lt;/P&gt;
&lt;P&gt;DS2016&lt;/P&gt;
&lt;P&gt;DS2017&lt;/P&gt;
&lt;P&gt;how can I compare or work with variables if i use a MERGE? some like...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I dont know how it works because I dont know how identify what variable is each for differente dataset&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When you merge that way, since you say that the two sets have the same varaible names then basically you are going to get the second data set&amp;nbsp;data that has matching ids. Merge keeps the variable value from the last listed dataset when the variable names are the same.&lt;/P&gt;
&lt;P&gt;Take a look at this brief example:&lt;/P&gt;
&lt;PRE&gt;data one;
   input id $ x;
datalines;
a  13
b  14
c  15
;

data two;
   input id $ x;
datalines;
b  23
c  24
d  25
;

data combined;
   merge
      one
      two
   ;
   by id;
run;&lt;/PRE&gt;
&lt;P&gt;You do not say what kind of comparison you are looking to do. If you need to know which dataset a variable value comes from you either 1)&amp;nbsp;rename all of the variables except id, or 2) SET instead of merge and add a variable to indicate the data set source or something else based on what you intend to follow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It helps to post example of your input data and the desired results for you input. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Descriptions of what type of comparison you need to do would also help. For instance there is PROC compare to examine differences or similarities on a record by record basis for all variables or use VAR and WITH for specific variables.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 18:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/It-is-possible-work-with-two-datasets-with-MERGE-both-with-same/m-p/332755#M74935</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-14T18:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: It is possible work with two datasets with MERGE both with same structure / same variable names?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/It-is-possible-work-with-two-datasets-with-MERGE-both-with-same/m-p/332757#M74937</link>
      <description>&lt;P&gt;To compare 2 datasets with identical structure, use proc compare.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 18:37:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/It-is-possible-work-with-two-datasets-with-MERGE-both-with-same/m-p/332757#M74937</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-14T18:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: It is possible work with two datasets with MERGE both with same structure / same variable names?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/It-is-possible-work-with-two-datasets-with-MERGE-both-with-same/m-p/332759#M74938</link>
      <description>&lt;P&gt;Using the example data that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;provided, something like the following would work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;libname lib 'c:\art';
data lib.one;
   input id $ x;
datalines;
a  13
b  14
c  15
;

data lib.two;
   input id $ x;
datalines;
b  23
c  24
d  25
;

data combined;
   merge
      lib.one (in=a keep=id x rename=(x=_x))
      lib.two (in=b)
   ;
   by id;
   if a and b;
   dif=x-_x;
run;

run;&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 18:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/It-is-possible-work-with-two-datasets-with-MERGE-both-with-same/m-p/332759#M74938</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-14T18:43:02Z</dc:date>
    </item>
  </channel>
</rss>

