<?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 Merge three datasets with different number of observations in each in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-three-datasets-with-different-number-of-observations-in/m-p/472984#M121323</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Is it possible to merge three datasets with different number of observations? Here SUBJECT is the unique identifier and other mentioned variables are only expected to be seen in the&amp;nbsp; output ( AMT, ASTTIMEPT, PRI)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the below code and see the following in the log.&lt;/P&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: MERGE statement has more than one data set with repeats of BY values.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 178 observations read from the data set WORK.AMT_.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 720 observations read from the data set WORK.AST_.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 88 observations read from the data set WORK.PRI_.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: The data set WORK.DER4 has 704 observations and 11 variables.&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data amt_;&lt;BR /&gt;set amt;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=amt_ ;&lt;BR /&gt;by&amp;nbsp;SUBJECT AMT;&amp;nbsp; /*There are two values for each subject, which are not duplicates*/&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data ast_;&lt;BR /&gt;set ast;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=ast_ ;&lt;BR /&gt;by SUBJECT ASTTIMEPT;&amp;nbsp; &amp;nbsp;/*There are 8 time points for each subject, which are not duplicates- Say Day0-Day7*/&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data pri_;&lt;BR /&gt;set pri;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=pri_;&lt;BR /&gt;by&amp;nbsp;SUBJECT PRI;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data der4;&lt;BR /&gt;merge amt_ (in=a) ast_ (in=b) pri_ (in=c);&lt;BR /&gt;by UNOSID;&lt;BR /&gt;if a;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Nasya&lt;/P&gt;</description>
    <pubDate>Mon, 25 Jun 2018 13:35:36 GMT</pubDate>
    <dc:creator>Nasya</dc:creator>
    <dc:date>2018-06-25T13:35:36Z</dc:date>
    <item>
      <title>Merge three datasets with different number of observations in each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-three-datasets-with-different-number-of-observations-in/m-p/472984#M121323</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Is it possible to merge three datasets with different number of observations? Here SUBJECT is the unique identifier and other mentioned variables are only expected to be seen in the&amp;nbsp; output ( AMT, ASTTIMEPT, PRI)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the below code and see the following in the log.&lt;/P&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: MERGE statement has more than one data set with repeats of BY values.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 178 observations read from the data set WORK.AMT_.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 720 observations read from the data set WORK.AST_.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 88 observations read from the data set WORK.PRI_.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: The data set WORK.DER4 has 704 observations and 11 variables.&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data amt_;&lt;BR /&gt;set amt;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=amt_ ;&lt;BR /&gt;by&amp;nbsp;SUBJECT AMT;&amp;nbsp; /*There are two values for each subject, which are not duplicates*/&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data ast_;&lt;BR /&gt;set ast;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=ast_ ;&lt;BR /&gt;by SUBJECT ASTTIMEPT;&amp;nbsp; &amp;nbsp;/*There are 8 time points for each subject, which are not duplicates- Say Day0-Day7*/&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data pri_;&lt;BR /&gt;set pri;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=pri_;&lt;BR /&gt;by&amp;nbsp;SUBJECT PRI;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data der4;&lt;BR /&gt;merge amt_ (in=a) ast_ (in=b) pri_ (in=c);&lt;BR /&gt;by UNOSID;&lt;BR /&gt;if a;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Nasya&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 13:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-three-datasets-with-different-number-of-observations-in/m-p/472984#M121323</guid>
      <dc:creator>Nasya</dc:creator>
      <dc:date>2018-06-25T13:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: Merge three datasets with different number of observations in each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-three-datasets-with-different-number-of-observations-in/m-p/472989#M121326</link>
      <description>&lt;P&gt;You haven't asked any question?&amp;nbsp; This step:&lt;/P&gt;
&lt;PRE&gt;data der4;
  merge amt_ (in=a) ast_ (in=b) pri_ (in=c);
  by unosid;
  if a;
run;&lt;/PRE&gt;
&lt;P&gt;Is stating to merge the 3 datasets by unosid, and keep records where data appears in amt_, i.e. if a subject only appears in ast_ then it would not appear in the output dataset.&amp;nbsp; That is what this tells you:&lt;/P&gt;
&lt;DIV class="sasNote"&gt;NOTE: MERGE statement has more than one data set with repeats of BY values.&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;NOTE: There were 178 observations read from the data set WORK.AMT_.&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;NOTE: There were 720 observations read from the data set WORK.AST_.&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;NOTE: There were 88 observations read from the data set WORK.PRI_.&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;NOTE: The data set WORK.DER4 has 704 observations and 11 variables.&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;So there are 6 observations (could be all same subject) which have subject value which does not appear in amt_.&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Please also avoid shouting in code, and use the code window - its the {i} above post area - to retain formatting.&lt;/DIV&gt;</description>
      <pubDate>Mon, 25 Jun 2018 13:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-three-datasets-with-different-number-of-observations-in/m-p/472989#M121326</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-25T13:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: Merge three datasets with different number of observations in each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-three-datasets-with-different-number-of-observations-in/m-p/472994#M121328</link>
      <description>Thanks for your response. I have another question.&lt;BR /&gt;NOTE: MERGE statement has more than one data set with repeats of BY values. Is this note a bad note and needs to be avoided?</description>
      <pubDate>Mon, 25 Jun 2018 13:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-three-datasets-with-different-number-of-observations-in/m-p/472994#M121328</guid>
      <dc:creator>Nasya</dc:creator>
      <dc:date>2018-06-25T13:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: Merge three datasets with different number of observations in each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-three-datasets-with-different-number-of-observations-in/m-p/473005#M121332</link>
      <description>&lt;P&gt;It is telling you have non-distinct by groups in one or more table.&amp;nbsp; There is lots of information out there on this topic for instance:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.lexjansen.com/nesug/nesug08/cc/cc21.pdf" target="_blank"&gt;https://www.lexjansen.com/nesug/nesug08/cc/cc21.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally, knowing your data is the most important part of any programming activity, (next to documentation of course).&amp;nbsp; So your question is actually to yourself, "&lt;SPAN&gt;Is this note a bad note and needs to be avoided?" - only you who know your data can answer this.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 13:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-three-datasets-with-different-number-of-observations-in/m-p/473005#M121332</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-25T13:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Merge three datasets with different number of observations in each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-three-datasets-with-different-number-of-observations-in/m-p/473009#M121333</link>
      <description>&lt;P&gt;No, you can't ignore the situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first step is forming a plan.&amp;nbsp; No computers allowed, since it's not a programming problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you have two observations in one data set, that should match with eight observations in another data set, what would you like the result to be?&amp;nbsp; SAS will match them, but it's probably not the match that you would choose.&amp;nbsp; (Actually SAS matches #1 with #1, then #2 with #2 through #8.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So plan.&amp;nbsp; What matches would create the proper result?&amp;nbsp; After that, we can talk about programming.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 14:07:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-three-datasets-with-different-number-of-observations-in/m-p/473009#M121333</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-06-25T14:07:57Z</dc:date>
    </item>
  </channel>
</rss>

