<?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 datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344184#M79079</link>
    <description>proc sort data=ds1;&lt;BR /&gt;proc sort data=ds2;&lt;BR /&gt;proc sort data=ds3;&lt;BR /&gt;by PTID;&lt;BR /&gt;run;&lt;BR /&gt;data ds4;&lt;BR /&gt;merge d1 (in=inds1) d2 (in=inds2) d3 (in=inds3);&lt;BR /&gt;by PTID;&lt;BR /&gt;if inds1 + inds2 + inds3 = 2;&lt;BR /&gt;MRNnew=compress(MRN,'7 9 'M'');&lt;BR /&gt;run;&lt;BR /&gt;title "Merged dataset";&lt;BR /&gt;proc print data=ds4;&lt;BR /&gt;run;&lt;BR /&gt;</description>
    <pubDate>Fri, 24 Mar 2017 19:26:59 GMT</pubDate>
    <dc:creator>Kavishah</dc:creator>
    <dc:date>2017-03-24T19:26:59Z</dc:date>
    <item>
      <title>Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344107#M79052</link>
      <description>&lt;P&gt;how do we&amp;nbsp;merge 3 datasets in sas by an observation which is found in exactly 2 of the 3 data sets&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 15:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344107#M79052</guid>
      <dc:creator>Kavishah</dc:creator>
      <dc:date>2017-03-24T15:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344122#M79054</link>
      <description>&lt;P&gt;Please expand on what you have and what you need. There are many ways of combining data sets and if there are any rules you need to provide them. Example data sets to represent EACH of your 3 sets and the desired result. The data sets should be in the form of data step code with enough variables and records to demonstrate the cases you expect to encounter in the full problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 16:38:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344122#M79054</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-24T16:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344143#M79061</link>
      <description>I have 3 datasets with different variables. I have to merge those 3 datasets with a common variable. And the observations for this variable should be present in exactly 2 datasets out of the 3. Does this help to provide a solution?</description>
      <pubDate>Fri, 24 Mar 2017 18:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344143#M79061</guid>
      <dc:creator>Kavishah</dc:creator>
      <dc:date>2017-03-24T18:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344154#M79063</link>
      <description>&lt;P&gt;It doesn't really help. &amp;nbsp;You haven't given examples of what the data sets would look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a guess that assumes your data sets are already sorted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;merge d1 (in=in1) d2 (in=in2) d3 (in=in3);&lt;/P&gt;
&lt;P&gt;by common_variable;&lt;/P&gt;
&lt;P&gt;if in1 + in2 + in3 = 2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 18:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344154#M79063</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-24T18:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344162#M79067</link>
      <description>data ds1 ;&lt;BR /&gt;input PTID MRN $9. ;&lt;BR /&gt;datalines ;&lt;BR /&gt;1 514779-MT&lt;BR /&gt;2 M200-8X&lt;BR /&gt;3 999-M&lt;BR /&gt;4 79750&lt;BR /&gt;;&lt;BR /&gt;data ds2 ;&lt;BR /&gt;input PTID WBC ;&lt;BR /&gt;datalines ;&lt;BR /&gt;4 450&lt;BR /&gt;3 340&lt;BR /&gt;2 .&lt;BR /&gt;5 870&lt;BR /&gt;6 .&lt;BR /&gt;;&lt;BR /&gt;data ds3 ;&lt;BR /&gt;input PTID WEIGHT ;&lt;BR /&gt;datalines ;&lt;BR /&gt;2 157&lt;BR /&gt;1 163&lt;BR /&gt;4 .&lt;BR /&gt;6 130&lt;BR /&gt;;&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Mar 2017 18:43:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344162#M79067</guid>
      <dc:creator>Kavishah</dc:creator>
      <dc:date>2017-03-24T18:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344163#M79068</link>
      <description>this is the data I have</description>
      <pubDate>Fri, 24 Mar 2017 18:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344163#M79068</guid>
      <dc:creator>Kavishah</dc:creator>
      <dc:date>2017-03-24T18:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344165#M79069</link>
      <description>Common variable is PTID</description>
      <pubDate>Fri, 24 Mar 2017 18:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344165#M79069</guid>
      <dc:creator>Kavishah</dc:creator>
      <dc:date>2017-03-24T18:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344167#M79070</link>
      <description>&lt;P&gt;Given those examples, what do you want the resulting file to look like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 18:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344167#M79070</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-24T18:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344169#M79072</link>
      <description>A table which has PTID's which are common to exactly 2 datasets out of the three.</description>
      <pubDate>Fri, 24 Mar 2017 18:55:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344169#M79072</guid>
      <dc:creator>Kavishah</dc:creator>
      <dc:date>2017-03-24T18:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344171#M79074</link>
      <description>&lt;P&gt;Then just sort your 3 files and use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;'s suggested code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 18:58:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344171#M79074</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-24T18:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344178#M79076</link>
      <description>That code does not give me the write output.</description>
      <pubDate>Fri, 24 Mar 2017 19:09:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344178#M79076</guid>
      <dc:creator>Kavishah</dc:creator>
      <dc:date>2017-03-24T19:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344179#M79077</link>
      <description>right*&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Mar 2017 19:12:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344179#M79077</guid>
      <dc:creator>Kavishah</dc:creator>
      <dc:date>2017-03-24T19:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344180#M79078</link>
      <description>&lt;P&gt;That's why I asked you what you want the resulting file to look like. Rather than simply repeating your description, show the desired resulting file in the form of a datastep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 19:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344180#M79078</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-24T19:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344184#M79079</link>
      <description>proc sort data=ds1;&lt;BR /&gt;proc sort data=ds2;&lt;BR /&gt;proc sort data=ds3;&lt;BR /&gt;by PTID;&lt;BR /&gt;run;&lt;BR /&gt;data ds4;&lt;BR /&gt;merge d1 (in=inds1) d2 (in=inds2) d3 (in=inds3);&lt;BR /&gt;by PTID;&lt;BR /&gt;if inds1 + inds2 + inds3 = 2;&lt;BR /&gt;MRNnew=compress(MRN,'7 9 'M'');&lt;BR /&gt;run;&lt;BR /&gt;title "Merged dataset";&lt;BR /&gt;proc print data=ds4;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Mar 2017 19:26:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344184#M79079</guid>
      <dc:creator>Kavishah</dc:creator>
      <dc:date>2017-03-24T19:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344188#M79081</link>
      <description>&lt;P&gt;I have NO idea what you are trying to explain with your incorrect use of the compress function, however, you use proc sorts with no by variable and try to merge 3 files that are different than those which you said you have. So, other than the new variable you are trying to create, does the following do the merge you wanted?:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sort data=ds1;
  by ptid;
run;

proc sort data=ds2;
  by ptid;
run;

proc sort data=ds3;
  by ptid;
run;

data want;
  merge ds1a (in=in1) ds2a (in=in2) ds3a (in=in3);
  by ptid;
  if in1 + in2 + in3 = 2;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 19:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344188#M79081</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-24T19:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Merge datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344201#M79083</link>
      <description>&lt;P&gt;Each PROC SORT requires its own BY statement.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 20:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-datasets/m-p/344201#M79083</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-24T20:08:11Z</dc:date>
    </item>
  </channel>
</rss>

