<?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: How to do a one-to-many merge while avoiding log note? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855177#M338011</link>
    <description>&lt;P&gt;Whenever you&amp;nbsp;&lt;EM&gt;expect&lt;/EM&gt; a one-to-many MERGE, but get this NOTE, your data is not what you expected, and you either need to get correct data in the first place, or deduplicate the datasets which are supposed to be unique with regards to the BY variable(s).&lt;/P&gt;</description>
    <pubDate>Mon, 23 Jan 2023 19:06:18 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-01-23T19:06:18Z</dc:date>
    <item>
      <title>How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855112#M337989</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The log note says "MERGE statement has more than one data set w/ repeats of BY values"&lt;/P&gt;
&lt;P&gt;How do i avoid it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1; 
infile datalines dsd dlm=",";
	input id $ visitnum var1 var2 var3 var4;
datalines;
001, 0, 56, 78, 39, 94,
001, 1, 54, 73, , ,
001, 1, 94, 95, , ,
001, 2, 94, 29, , ,
002, 0, 57, 73, 23, 11,
002, 1, 51, 75, , ,
002, 1, 90, 91, , ,
002, 2, 89, 30, , ,
;
run;

data have2;
infile datalines dsd dlm=",";
	input id $ visitnum var3 var4;
datalines;
001, 1, 40, 96
002, 1, 24, 14
;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;desired output:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Hello_there_0-1674489371244.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79618i793EADC94C0B1B07/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Hello_there_0-1674489371244.png" alt="Hello_there_0-1674489371244.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 15:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855112#M337989</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-01-23T15:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855117#M337990</link>
      <description>&lt;P&gt;You can avoid it by doing merges that are not one-to-many but are one-to-one, if possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, NOTEs are a good thing, you shouldn't want to avoid them, this could lead to some unexpected and unpleasant outcomes.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 16:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855117#M337990</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-23T16:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855118#M337991</link>
      <description>I wish i could, but this is necessary for my use case. My logs get checked and unfortunately this would not pass and i would have to redo it. Is there a way to do this in PROC SQL?</description>
      <pubDate>Mon, 23 Jan 2023 16:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855118#M337991</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-01-23T16:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855120#M337992</link>
      <description>&lt;P&gt;By not having more than one dataset that has "many".&lt;/P&gt;
&lt;P&gt;Your example data does not have any trouble.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;340  data want ;
341    merge have1 have2 ;
342    by id visitnum;
343  run;

NOTE: There were 8 observations read from the data set WORK.HAVE1.
NOTE: There were 2 observations read from the data set WORK.HAVE2.
NOTE: The data set WORK.WANT has 8 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which of the two dataset should be the "one" dataset?&amp;nbsp; Is it HAVE2?&lt;/P&gt;
&lt;P&gt;To test if HAVE2 has duplicates run a test like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2_unique have2_dups;
  set have2 ;
  by id visitnum;
  if first.visitnum then output have2_unique;
  if not (first.visitnum and last.visitnum) then output have2_dups;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 16:13:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855120#M337992</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-23T16:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855121#M337993</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Your sample data doesn't generate those notes&lt;/STRONG&gt;. Show the code used, especially because you have multiple variables that overlap (id visitnum var3 var4).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect your actual data has duplicates in each of the files so you have a many to many merge, not a one to many merge.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 69         data want;
 70         merge have1 have2;
 71         by id ;
 72         run;
 
 NOTE: There were 8 observations read from the data set WORK.HAVE1.
 NOTE: There were 2 observations read from the data set WORK.HAVE2.
 NOTE: The data set WORK.WANT has 8 observations and 8 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              1241.06k
       OS Memory           20908.00k
       Timestamp           01/23/2023 04:16:32 PM
       Step Count                        61  Switch Count  2
       Page Faults                       0
       Page Reclaims                     247
       Page Swaps                        0
       Voluntary Context Switches        9
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264
       
 
 73         
 74         data want;
 75         merge have1 have2;
 76         by id visitnum;
 77         run;
 
 NOTE: There were 8 observations read from the data set WORK.HAVE1.
 NOTE: There were 2 observations read from the data set WORK.HAVE2.
 NOTE: The data set WORK.WANT has 8 observations and 8 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              1251.15k
       OS Memory           20908.00k
       Timestamp           01/23/2023 04:16:32 PM
       Step Count                        62  Switch Count  2
       Page Faults                       0
       Page Reclaims                     184
       Page Swaps                        0
       Voluntary Context Switches        10
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           272
       &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Jan 2023 16:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855121#M337993</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-23T16:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855136#M337995</link>
      <description>Hi Tom,&lt;BR /&gt;Thanks for taking time to reply. My example data was not good, so that's why the log note didn't populate. I was in a hurry and couldn't think of good enough data to replicate it. &lt;BR /&gt;&lt;BR /&gt;The good news it that i solved my problem by renaming the variables and doing a proc sql left join. &lt;BR /&gt;Thanks again!</description>
      <pubDate>Mon, 23 Jan 2023 16:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855136#M337995</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-01-23T16:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855138#M337996</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi Tom,&lt;BR /&gt;Thanks for taking time to reply. My example data was not good, so that's why the log note didn't populate. I was in a hurry and couldn't think of good enough data to replicate it. &lt;BR /&gt;&lt;BR /&gt;The good news it that i solved my problem by renaming the variables and doing a proc sql left join. &lt;BR /&gt;Thanks again!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Unless you got rid of the duplicates you didn't solve the underlying problem, you just used a tool that wouldn't complain about it.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 16:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855138#M337996</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-23T16:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855139#M337997</link>
      <description>Hi Reeza,&lt;BR /&gt;Thanks for looking at my issue. My example code was hastily done so I couldn't think of a good way to replicate my issue.&lt;BR /&gt;I did however solve my issue by renaming my variables and doing a proc sql left join.&lt;BR /&gt;Thanks though for looking at it.</description>
      <pubDate>Mon, 23 Jan 2023 16:29:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855139#M337997</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-01-23T16:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855140#M337998</link>
      <description>&lt;P&gt;So,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;according to the others, these notes are a good things, they are caused by many-to-many merges, which is not what you thought you were doing.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 16:29:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855140#M337998</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-23T16:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855142#M337999</link>
      <description>&lt;P&gt;The issue is that for my use case, there are multiple values of the by statement bc there were two identical visits and no other unique variable to further make the key variables distinct. It is common for there to be messy data and sometimes it requires a somewhat unrefined solution. &lt;BR /&gt;&lt;BR /&gt;But you could be right that i didn't address the underlying problem which might cause potential issues later on, I have to investigate further and collaborate w/ someone to see if they come to the same output as me.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 16:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855142#M337999</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-01-23T16:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855143#M338000</link>
      <description>Hi PaigeMiller,&lt;BR /&gt;&lt;BR /&gt;I think my example was not a good one and not reflective of the true nature of my problem. &lt;BR /&gt;I did come up with a rather unrefined solution, but i think it achieved the end result of what i wanted.&lt;BR /&gt;</description>
      <pubDate>Mon, 23 Jan 2023 16:35:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855143#M338000</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-01-23T16:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855153#M338003</link>
      <description>SQL wouldn't have fixed your issue, your join conditions need to be modified.</description>
      <pubDate>Mon, 23 Jan 2023 17:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855153#M338003</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-23T17:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855177#M338011</link>
      <description>&lt;P&gt;Whenever you&amp;nbsp;&lt;EM&gt;expect&lt;/EM&gt; a one-to-many MERGE, but get this NOTE, your data is not what you expected, and you either need to get correct data in the first place, or deduplicate the datasets which are supposed to be unique with regards to the BY variable(s).&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 19:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855177#M338011</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-23T19:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855179#M338013</link>
      <description>&lt;P&gt;If you really did want a many-to-many result set to start with then the SQL you ended up with is the best option.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 19:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855179#M338013</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-01-23T19:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855196#M338020</link>
      <description>&lt;P&gt;Isn't many defined as duplicates of by variables?&lt;BR /&gt;&lt;BR /&gt;In my case, isn't my "many" the duplicates of id and visitnum when the visit is equal to 1? In other words, two id=001, visitnum=1 and two id=002, vistnum=1.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 19:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855196#M338020</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-01-23T19:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a one-to-many merge while avoiding log note?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855204#M338027</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Isn't many defined as duplicates of by variables?&lt;BR /&gt;&lt;BR /&gt;In my case, isn't my "many" the duplicates of id and visitnum when the visit is equal to 1? In other words, two id=001, visitnum=1 and two id=002, vistnum=1.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No.&amp;nbsp; Your example is showing two distinct values since the variable ID is different.&amp;nbsp; It would only be consider MANY if you use only VISITNUM as the key, but that does not make much sense with the data you posted.&amp;nbsp; If VISITNUM was the key then you should not have the ID variable on both datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If both dataset have ID and VISITNUM then those should be the keys.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use only one of them as the key then you should not have the other in both dataset.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 20:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-one-to-many-merge-while-avoiding-log-note/m-p/855204#M338027</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-23T20:22:14Z</dc:date>
    </item>
  </channel>
</rss>

