<?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: proc merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798345#M313854</link>
    <description>&lt;P&gt;That's why &lt;EM&gt;real&lt;/EM&gt; programmers (those who can type in bootstrap code in hex from the console of a mainframe, joke intended) never use the asterisk in joins, but an exhaustive list of variables.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;In your code, this would be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table joined as
select
  coalesce(t1.id,t2.id) as id,
  t1.left,
  t2.right 
from left t1
full join right t2
 on t1.id=t2.id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which would also solve the missing issue for observations contained only in the second dataset.&lt;/P&gt;</description>
    <pubDate>Thu, 24 Feb 2022 09:06:34 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-02-24T09:06:34Z</dc:date>
    <item>
      <title>SAS merge SQL equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798286#M313828</link>
      <description>&lt;P&gt;what is SAS merge in sql language, is it full outer join?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 07:18:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798286#M313828</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-02-24T07:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: proc merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798290#M313830</link>
      <description>&lt;P&gt;It isn't.&lt;/P&gt;
&lt;P&gt;Closest is a FULL JOIN but you can use the flags created by the IN= dataset option to do LEFT, RIGHT or INNER also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the behavior in Many to Many situations is different.&lt;/P&gt;
&lt;P&gt;In an SQL join every observation in the left table is matched to every observation in the right table.&amp;nbsp; So a group of 3 joined to a group of 2 results in 6 observations.&lt;/P&gt;
&lt;P&gt;In a data step MERGE the observations are matched in the order they are retrieved.&amp;nbsp; So a group of 3 merged with a group of 2 results in 3 observations.&amp;nbsp; The values of unique fields from the smaller group's last observation are retained (really just not replaced) for the rest of the observations in the group.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 02:04:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798290#M313830</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-24T02:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: proc merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798293#M313831</link>
      <description>&lt;P&gt;can you provide a simple example?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 02:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798293#M313831</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-02-24T02:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: proc merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798296#M313833</link>
      <description>&lt;P&gt;You can make your own. But here is a simple example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data left;
 input id left $;
cards;
1 A
1 B
1 C
2 D
3 E
;

data right ;
  input id right $;
cards;
1 Z
1 Y
3 X
3 W
4 V
;

data merged ;
  merge left right ;
  by id;
run;

proc sql;
create table joined as
select * 
from left
full join right
 on left.id=right.id
;
quit;

proc print data=merged;
  title 'merged';
run;
proc print data=joined;
  title 'joined';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-02-23 211001.jpg" style="width: 248px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68804i9976D6E384443B15/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-02-23 211001.jpg" alt="Screenshot 2022-02-23 211001.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;And I forgot that SQL joins are too stupid to realize that your key variables should be same.&amp;nbsp; When you try to name two variables with the same name in an SQL SELECT list of variables only the first variable with that name will make it into the dataset.&amp;nbsp; So the last observation in the JOINED dataset is missing the ID value since it did not exist in the LEFT dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could get around this by using NATURAL join,&amp;nbsp; but then you lose direct control of the criteria of the join, which one of the nice features of an SQL join.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 02:16:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798296#M313833</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-24T02:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: proc merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798300#M313836</link>
      <description>&lt;P&gt;Various forms of merges are covered here in the documentation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/n1tgk0uanvisvon1r26lc036k0w7.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/n1tgk0uanvisvon1r26lc036k0w7.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note there is no 'proc merge', &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;is assuming you're referring to a data step merge but you've also mentioned a SQL merge so it's unclear to me.&amp;nbsp;&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/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;what is SAS merge in sql language, is it full outer join?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 02:16:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798300#M313836</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-24T02:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: proc merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798301#M313837</link>
      <description>&lt;P&gt;Merge also treats same named variables from both sets quite a bit differently than SQL joins do. As in, you only get one variable by a given name in the data vector so the values from one set will replace the other.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 02:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798301#M313837</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-24T02:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798345#M313854</link>
      <description>&lt;P&gt;That's why &lt;EM&gt;real&lt;/EM&gt; programmers (those who can type in bootstrap code in hex from the console of a mainframe, joke intended) never use the asterisk in joins, but an exhaustive list of variables.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;In your code, this would be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table joined as
select
  coalesce(t1.id,t2.id) as id,
  t1.left,
  t2.right 
from left t1
full join right t2
 on t1.id=t2.id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which would also solve the missing issue for observations contained only in the second dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 09:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798345#M313854</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-24T09:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS merge SQL equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798346#M313855</link>
      <description>&lt;P&gt;It's neither, because a MERGE in a DATA step behaves completely different in many-to-many joins.&lt;/P&gt;
&lt;P&gt;And how the MERGE behaves in one-to-many, many-to-one or one-to-one joins is controlled by subsetting IF's using the IN= variables, so even there there is no true answer.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 09:10:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/798346#M313855</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-24T09:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: proc merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/840086#M332169</link>
      <description>&lt;P&gt;do you mean if it is not many to many, can be interpreted by left, right or inner join&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if it is many to many then it cannot be replicated by any sql join and specific programming is required?&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2022 13:56:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/840086#M332169</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-10-22T13:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: proc merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/840089#M332170</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if it is many to many then it cannot be replicated by any sql join and specific programming is required?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes. Very often a many to many MERGE in a data step is tolerated because the relevant variables in one dataset sr'tay constant for a group. In this case, you should deduplicate first in SQL before doing the main join.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2022 14:28:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/840089#M332170</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-22T14:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: proc merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/840092#M332173</link>
      <description>&lt;PRE&gt;data samp_acct_card;

merge samp_acct_card(in=a) relation (keep=relationship_no in =b);

by relationship_no;

if a;

if b and samp_ex=" and IND_CENTRAL_LIMIT in ('Y','1') then samp_ex="DEFAULT_CENTRAL_LMT';

run;&lt;/PRE&gt;
&lt;P&gt;when I see the line 'if a', I'd like to think this is a left join, but with the next line 'if b....'&lt;/P&gt;
&lt;P&gt;I dont know what kind of join this is, please assist. thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2022 15:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/840092#M332173</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-10-22T15:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: proc merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/840094#M332174</link>
      <description>&lt;P&gt;STOP thinking of data step MERGEs in SQL terms. As long as you keep this illusion, you'll never get anywhere.&lt;/P&gt;
&lt;P&gt;A data step processes observations in one or more datasets &lt;EM&gt;sequentially&lt;/EM&gt;. SQL, OTOH, works with&amp;nbsp;&lt;EM&gt;sets&lt;/EM&gt; of records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first IF is a&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p1cxl8ifdt8u0gn12wqbji8o5fq1.htm" target="_blank" rel="noopener"&gt;Subsetting IF&lt;/A&gt;&amp;nbsp;(&lt;STRONG&gt;PLEASE&lt;/STRONG&gt; study the documentation!), while the second is a "normal" IF which executes a statement depending on a condition.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2022 16:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/840094#M332174</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-22T16:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAS merge SQL equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/840096#M332176</link>
      <description>&lt;P&gt;For such questions it's often worth to search if the SAS documentation provides some information.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found the following via Google search with keywords:&amp;nbsp;&lt;EM&gt;sas help center 9.4 sql merge compare&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p1v0kcf40q6x7mn1pu5hl4s9ux48.htm" target="_blank" rel="noopener"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p1v0kcf40q6x7mn1pu5hl4s9ux48.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...and after searching one more minute also these links:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1i8w2bwu1fn5kn1gpxj18xttbb0.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1i8w2bwu1fn5kn1gpxj18xttbb0.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/p0o4a5ac71mcchn1kc1zhxdnm139.htm#n0pess5znhf9fdn1tej6r0gff0vo" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/p0o4a5ac71mcchn1kc1zhxdnm139.htm#n0pess5znhf9fdn1tej6r0gff0vo&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p1phdzzlrc1wi8n1bpigstwt851o.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p1phdzzlrc1wi8n1bpigstwt851o.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you read all this information in detail as once fully understood it will help you to solve a myriad of cases.&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;</description>
      <pubDate>Sat, 22 Oct 2022 16:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/840096#M332176</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-10-22T16:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS merge SQL equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/840108#M332187</link>
      <description>&lt;P&gt;Neither, it's more like a cursor equivalent as it processes row by row.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2022 18:48:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-SQL-equivalent/m-p/840108#M332187</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-22T18:48:49Z</dc:date>
    </item>
  </channel>
</rss>

