<?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 By Variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960847#M43175</link>
    <description>&lt;P&gt;So that picture looks nothing like your original example.&amp;nbsp; Which variables corresponds with ID and VALUE1 that you had in your example?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you mean you want ZIPCODE to "repeat"?&amp;nbsp; In your picture there are many values or ZIPCODE already shown.&amp;nbsp; How is it not repeating?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that your example showed a 1 to N match.&amp;nbsp; Each observation in HAVE1 was merged with zero or more observations in HAVE2.&amp;nbsp; That is what a MERGE can handle.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you instead want an N to M match then you cannot use a MERGE.&amp;nbsp; Instead you will need to preform a cartesian product, like what the INNER JOIN of SQL produces.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Mar 2025 15:44:30 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-03-04T15:44:30Z</dc:date>
    <item>
      <title>Merging By Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960769#M43169</link>
      <description>&lt;P&gt;I'm not sure what's going on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have these two datasets&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input id value1 $;
cards;
1 a
2 a
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
input id zipcode;
cards;
1 88888
1 99999
2 88888
2 99999
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I want this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input id value1 $ zipcode;
cards;
1 a 88888
1 a 99999
2 a 88888
2 a 99999
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried merging the two datasets by id, but it is not repeating the way i want. I feel like I'm missing something obvious.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Mar 2025 19:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960769#M43169</guid>
      <dc:creator>JJ_83</dc:creator>
      <dc:date>2025-03-03T19:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merging By Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960774#M43170</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    merge have1 have2;
    by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Mar 2025 19:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960774#M43170</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-03-03T19:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Merging By Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960775#M43171</link>
      <description>&lt;P&gt;Show your merge code, please. When I ran this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	merge have1 have2;
	by id;
run;
proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result was this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 192pt;" border="0" width="256" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="4" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD width="64" height="21" class="xl63" style="height: 15.75pt; width: 48pt;"&gt;Obs&lt;/TD&gt;
&lt;TD width="64" class="xl64" style="border-left: none; width: 48pt;"&gt;id&lt;/TD&gt;
&lt;TD width="64" class="xl64" style="border-left: none; width: 48pt;"&gt;value1&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;zipcode&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;a&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl68" style="border-top: none; border-left: none; width: 48pt;"&gt;88888&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;2&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;a&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl68" style="border-top: none; border-left: none; width: 48pt;"&gt;99999&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;3&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;2&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;a&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl68" style="border-top: none; border-left: none; width: 48pt;"&gt;88888&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD width="64" height="21" class="xl69" style="height: 15.75pt; border-top: none; width: 48pt;"&gt;4&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl70" style="border-top: none; border-left: none; width: 48pt;"&gt;2&lt;/TD&gt;
&lt;TD width="64" class="xl70" style="border-top: none; border-left: none; width: 48pt;"&gt;a&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl71" style="border-top: none; border-left: none; width: 48pt;"&gt;99999&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Isn't that exactly what you wanted?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Mar 2025 19:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960775#M43171</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2025-03-03T19:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Merging By Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960778#M43172</link>
      <description>&lt;P&gt;For some reason that merge statement isn't doing what I want it to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want each zipcode value to repeat for each pwsid entry, but it's not doing that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JJ_83_0-1741032467507.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105119i2EB48FD43FF18BAC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JJ_83_0-1741032467507.png" alt="JJ_83_0-1741032467507.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Mar 2025 20:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960778#M43172</guid>
      <dc:creator>JJ_83</dc:creator>
      <dc:date>2025-03-03T20:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Merging By Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960779#M43173</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table working.p42 as
    select a.*, b.zipcode
    from working.ucmr3 as a
    inner join working.ucmr3_zip as b
    on a.pwsid = b.pwsid;
quit; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Chat GPT helped me with this. This code worked.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Mar 2025 20:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960779#M43173</guid>
      <dc:creator>JJ_83</dc:creator>
      <dc:date>2025-03-03T20:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Merging By Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960803#M43174</link>
      <description>&lt;P&gt;You would have to provide examples of the data sets and the code.&lt;/P&gt;
&lt;P&gt;You don't even tell us exactly what is wrong with that "example" data. &lt;/P&gt;
&lt;P&gt;IF your "merge" was by PWSID then to get all Zipcodes duplicated from a merged data set then PWSID could only appear &lt;STRONG&gt;once&amp;nbsp;&lt;/STRONG&gt;in the base set and then have the value of PWSID with each desired Zip code in the other set. Once you have duplicates of a BY variable in two or more sets in a data step merge the results often get much more problematic because of the way the Merge statement works. Did you read the log? Did it have anything about "more than one data set with repeats of BY values" ? That warning tells you that you likely don't have the desired result because if there are&amp;nbsp;&amp;nbsp; N duplicates of a By variable valie in one set and M duplicates of the same value in the other the resulting set will generally have one of N or M resulting by variable values depending on the data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;Data ex1;
  input id  x $;
datalines;
1  a
1  b 
1  c
2  q
;

data ex2;
  input id y $;
datalines;
1   zz
1   yy
2   qq
2   hh
;

data combined;
  merge ex1 ex2;
  by id;
run;&lt;/PRE&gt;
&lt;P&gt;Note that the output data set Combined will have 5 observation not the 8 you were wanting, if I understand: 3 values of Id=1 (not the 6 that a 3x2 cross would generate) and 2 values of Id=2.&lt;/P&gt;
&lt;P&gt;Do note the LOG (emphasis added):&lt;/P&gt;
&lt;PRE&gt;19   data combined;
20     merge ex1 ex2;
21     by id;
22   run;

&lt;FONT size="5" color="#800080"&gt;&lt;STRONG&gt;NOTE: MERGE statement has more than one data set with repeats of BY values.&lt;/STRONG&gt;&lt;/FONT&gt;
NOTE: There were 4 observations read from the data set WORK.EX1.
NOTE: There were 4 observations read from the data set WORK.EX2.
NOTE: The data set WORK.COMBINED has 5 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;Also note that the single Id=2 did get both the other values added.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329582"&gt;@JJ_83&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;For some reason that merge statement isn't doing what I want it to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want each zipcode value to repeat for each pwsid entry, but it's not doing that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JJ_83_0-1741032467507.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105119i2EB48FD43FF18BAC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JJ_83_0-1741032467507.png" alt="JJ_83_0-1741032467507.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 00:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960803#M43174</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-03-04T00:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: Merging By Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960847#M43175</link>
      <description>&lt;P&gt;So that picture looks nothing like your original example.&amp;nbsp; Which variables corresponds with ID and VALUE1 that you had in your example?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you mean you want ZIPCODE to "repeat"?&amp;nbsp; In your picture there are many values or ZIPCODE already shown.&amp;nbsp; How is it not repeating?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that your example showed a 1 to N match.&amp;nbsp; Each observation in HAVE1 was merged with zero or more observations in HAVE2.&amp;nbsp; That is what a MERGE can handle.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you instead want an N to M match then you cannot use a MERGE.&amp;nbsp; Instead you will need to preform a cartesian product, like what the INNER JOIN of SQL produces.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 15:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960847#M43175</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-03-04T15:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Merging By Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960849#M43176</link>
      <description>&lt;P&gt;I don't need more feedback, it's been solved. Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 15:47:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960849#M43176</guid>
      <dc:creator>JJ_83</dc:creator>
      <dc:date>2025-03-04T15:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Merging By Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960850#M43177</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I don't need more feedback, it's been solved. Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 15:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-By-Variable/m-p/960850#M43177</guid>
      <dc:creator>JJ_83</dc:creator>
      <dc:date>2025-03-04T15:48:35Z</dc:date>
    </item>
  </channel>
</rss>

