<?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 many datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/882497#M348650</link>
    <description>&lt;P&gt;Which observation do you want when there are multiples?&lt;/P&gt;
&lt;P&gt;The first one?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data first;
  merge DM1 sv2  vs1x ex3 ds1x ;
  by usubjid;
  if first.usubjid ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or the last one?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data first;
  merge DM1 sv2  vs1x ex3 ds1x ;
  by usubjid;
  if last.usubjid ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 26 Jun 2023 17:59:58 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-06-26T17:59:58Z</dc:date>
    <item>
      <title>merging many datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881539#M348326</link>
      <description>&lt;P&gt;please I need help merging multiple datsets(5 datasets);&amp;nbsp;&lt;/P&gt;&lt;P&gt;data adsl;&lt;BR /&gt;merge dm1(in=a) ds1x(in=b) ex3(in=c) vs1x(in=d) sv2(in=e);&lt;BR /&gt;by usubjid;&lt;BR /&gt;if in (a, b, c, d, e);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;When I merge these datasets it generate this message in the log;&amp;nbsp;MERGE statement has more than one data set with repeats of BY values.&lt;/P&gt;&lt;P&gt;when I merged two at a time, I didn't get the message except with sv2;&lt;/P&gt;&lt;P&gt;data adslx;&lt;BR /&gt;merge dm1(in=a) ds1x(in=b);&lt;BR /&gt;by usubjid;&lt;BR /&gt;if a and b;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data adsly;&lt;BR /&gt;merge vs1x(in=a) ex3(in=b);&lt;BR /&gt;by usubjid;&lt;BR /&gt;if a and b;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;The message( MERGE statement has more than one data set with repeats of BY values) occurred in the log again when decide to merge adslx and adsly&lt;/P&gt;&lt;P&gt;data merge_adsl;&lt;BR /&gt;merge adslx(in=a) adsly(in=b);&lt;BR /&gt;by usubjid;&lt;BR /&gt;if a and b;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, how can I resolve this issue?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 13:13:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881539#M348326</guid>
      <dc:creator>PrinceAde</dc:creator>
      <dc:date>2023-06-20T13:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: merging many datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881545#M348328</link>
      <description>&lt;P&gt;Hi it would be great to provide a portion of data, even dummy, for testing.&lt;BR /&gt;There was a similar post&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Studio/MERGE-statement-has-more-than-one-data-set-with-repeats-of-BY/td-p/449980" target="_blank"&gt;https://communities.sas.com/t5/SAS-Studio/MERGE-statement-has-more-than-one-data-set-with-repeats-of-BY/td-p/449980&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;I would also try the syntax :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if A and B and C and D and E;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;in lieu of : if in (a, b, c, d, e);&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 14:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881545#M348328</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-06-20T14:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: merging many datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881546#M348329</link>
      <description>&lt;P&gt;The best solution would likely be to fix the data sets before you merge them.&amp;nbsp; More specifically, why should the same USUBJID have two observations in the same data set?&amp;nbsp; In fact, it has two (or more) observations in more than one incoming data set.&amp;nbsp; That's what the message tells you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can't make USUBJID unique, then you have to choose among more complex scenarios&amp;nbsp; For example, what result do you want if the same USUBJID appears three times in one data set, and twice in another?&amp;nbsp; That's a choice that depends on your knowledge of what is in the data (or what should be in the data).&amp;nbsp; Start with making USUBJID unique if that's at all possible.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 14:38:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881546#M348329</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-06-20T14:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: merging many datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881562#M348333</link>
      <description>&lt;P&gt;You may want to run this small example of merging sets with repeats of BY values in two (or more) sets to see what may happen with the values of other variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data ex1;
   input a b;
datalines;
1 1
1 2
1 3
1 4
;

data ex2;
   input a c;
datalines;
1 11
1 22
;

data merged;
   merge ex1 ex2;
   by a;
run;&lt;/PRE&gt;
&lt;P&gt;The "resolution" depends on what you need for a result when multiple sets have multiple values of the BY variables. So you need describe what the resulting data is supposed to have in that situation.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 17:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881562#M348333</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-06-20T17:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: merging many datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881665#M348369</link>
      <description>&lt;P&gt;My final target is one record per subject. I made the usubjid&amp;nbsp; unique before merging. It works.&lt;/P&gt;&lt;P&gt;I appreciate.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 09:36:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881665#M348369</guid>
      <dc:creator>PrinceAde</dc:creator>
      <dc:date>2023-06-21T09:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: merging many datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881668#M348372</link>
      <description>&lt;P&gt;The link was very helpful, I created unique usubjid before merging;&amp;nbsp;My final target is one record per subject.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 10:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881668#M348372</guid>
      <dc:creator>PrinceAde</dc:creator>
      <dc:date>2023-06-21T10:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: merging many datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881674#M348377</link>
      <description>&lt;P&gt;I hear you.&amp;nbsp; But SAS disagrees.&amp;nbsp; The message it is giving means that at least two of your incoming data sets contain multiple observations for a USUBJID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a program you can run to find the source of the problem in the DM1 data set:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=dm1 noprint;
   tables usubjid / out=dm1_multiples (where=(count &amp;gt; 1) drop=percent);
run;
proc print data=dm1_multiples;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Unfortunately, you will need to test all the data sets.&amp;nbsp; Since you are expecting no such problem, it is possible the problem lies with missing values:&amp;nbsp; multiple observations where USUBJID has a missing value.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 11:07:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/881674#M348377</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-06-21T11:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: merging many datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/882442#M348633</link>
      <description>&lt;P&gt;Hello sir.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sorry for replying so late.&lt;/P&gt;&lt;P&gt;DM1 contains 742 observations. When I applied the recommendation above, dm1_multiples gave me 0 obs.&lt;/P&gt;&lt;P&gt;The remaining datasets, sv2_multiples, vs1x_multiples, ex3_multiples, and ds1x_multiples all give 742 obs, which are all unique. This appears to have removed duplicate obs, just like nodupkeys.&lt;/P&gt;&lt;P&gt;I expect to get one obs per record in my final dataset, which is 742 observations.&lt;/P&gt;&lt;P&gt;What do you advise, sir?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2023 14:10:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/882442#M348633</guid>
      <dc:creator>PrinceAde</dc:creator>
      <dc:date>2023-06-26T14:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: merging many datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/882497#M348650</link>
      <description>&lt;P&gt;Which observation do you want when there are multiples?&lt;/P&gt;
&lt;P&gt;The first one?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data first;
  merge DM1 sv2  vs1x ex3 ds1x ;
  by usubjid;
  if first.usubjid ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or the last one?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data first;
  merge DM1 sv2  vs1x ex3 ds1x ;
  by usubjid;
  if last.usubjid ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Jun 2023 17:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-many-datasets/m-p/882497#M348650</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-26T17:59:58Z</dc:date>
    </item>
  </channel>
</rss>

