<?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 SQL - left join on multiple variables - Warning that variables already exist in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-left-join-on-multiple-variables-Warning-that-variables/m-p/609193#M17837</link>
    <description>Does that mean that I do not need to use a SELECT statement for alias A?</description>
    <pubDate>Tue, 03 Dec 2019 21:43:06 GMT</pubDate>
    <dc:creator>LEINAARE</dc:creator>
    <dc:date>2019-12-03T21:43:06Z</dc:date>
    <item>
      <title>Proc SQL - left join on multiple variables - Warning that variables already exist</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-left-join-on-multiple-variables-Warning-that-variables/m-p/609185#M17833</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with two very large datasets and would like to use PROC SQL to merge a variable (AdmDiag10) from a dataset (new.&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;AdmDiag10&lt;/SPAN&gt;_merge) onto another dataset to avoid unnecessary sort procedures.&amp;nbsp; The&amp;nbsp;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;new.&lt;/SPAN&gt;&lt;SPAN style="background-color: #ffffff; color: #333333; cursor: text; display: inline; float: none; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 1.2; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;AdmDiag10&lt;/SPAN&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;_merge&lt;/SPAN&gt; dataset has only five variables, the four need to merge the records and the new variable (&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;AdmDiag10&lt;/SPAN&gt;).&amp;nbsp; Since I am more comfortable using data steps, I am including below the program I &lt;EM&gt;&lt;U&gt;would use&lt;/U&gt;&lt;/EM&gt; (if I wanted to use a data step) to help communicate what I am trying to achieve with a left join.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Data step I would use to achieve desired merge*/
data medical_1217;
	merge medical_1217 (in=a)
		new.admdiag10_merge;
	by orsid recordid log file_type;
	if a = 1;
run;


/*SQL Procedure I have developed to attempt a similar join*/
proc sql;
	create table test as
	select a.*, b.*
	from medical_1217 a
	left join new.admdiag10_merge b
	on a.orsid = b.orsid
	and a.recordid = b.recordid
	and a.log = b.log
	and a.file_type = b.file_type;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the PROC SQL program, I get warning messages for each variable used to join on.&amp;nbsp; Can someone please explain what is going on here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ted&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 21:28:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-left-join-on-multiple-variables-Warning-that-variables/m-p/609185#M17833</guid>
      <dc:creator>LEINAARE</dc:creator>
      <dc:date>2019-12-03T21:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - left join on multiple variables - Warning that variables already exist</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-left-join-on-multiple-variables-Warning-that-variables/m-p/609190#M17835</link>
      <description>&lt;P&gt;Your warning is coming from this bit of code:&lt;/P&gt;
&lt;PRE&gt;proc sql;
	create table test as
	select a.*, b.*
&lt;/PRE&gt;
&lt;P&gt;The * requests ALL the variables. So since both alias A and B have at least 4 variables in common you have requested duplicates for the variables. The JOIN has nothing to do with the warning. Observe:&lt;/P&gt;
&lt;PRE&gt;1730  proc sql ;
1731     create table work.junk as
1732     select name , name
1733     from sashelp.class
1734     ;
WARNING: Variable Name already exists on file WORK.JUNK.
NOTE: Table WORK.JUNK created, with 19 rows and 1 columns.
&lt;/PRE&gt;
&lt;P&gt;It is the mention of the same variable name.&lt;/P&gt;
&lt;P&gt;If you do not want the warning then only list the variables from B that you want to add to A, or vice versa. Just mention a variable name once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately data steps don't do well with multiple records with the same BY variables in both sets when using Merge and won't allow multiple records in the base set if using UPDATE. So SQL is often the appropriate tool.&lt;/P&gt;
&lt;P&gt;Of course SQL can be extremely verbose due to the syntax requirements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 21:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-left-join-on-multiple-variables-Warning-that-variables/m-p/609190#M17835</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-03T21:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - left join on multiple variables - Warning that variables already exist</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-left-join-on-multiple-variables-Warning-that-variables/m-p/609192#M17836</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks for your response. I am not very savvy with proc SQL. Could you please explain what you mean by "If you do not want the warning then only list the variables from B that you want to add to A, or vice versa. Just mention a variable name once."</description>
      <pubDate>Tue, 03 Dec 2019 21:41:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-left-join-on-multiple-variables-Warning-that-variables/m-p/609192#M17836</guid>
      <dc:creator>LEINAARE</dc:creator>
      <dc:date>2019-12-03T21:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - left join on multiple variables - Warning that variables already exist</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-left-join-on-multiple-variables-Warning-that-variables/m-p/609193#M17837</link>
      <description>Does that mean that I do not need to use a SELECT statement for alias A?</description>
      <pubDate>Tue, 03 Dec 2019 21:43:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-left-join-on-multiple-variables-Warning-that-variables/m-p/609193#M17837</guid>
      <dc:creator>LEINAARE</dc:creator>
      <dc:date>2019-12-03T21:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - left join on multiple variables - Warning that variables already exist</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-left-join-on-multiple-variables-Warning-that-variables/m-p/609199#M17839</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203435"&gt;@LEINAARE&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Does that mean that I do not need to use a SELECT statement for alias A?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No.&lt;/P&gt;
&lt;P&gt;As a minimum you likely want a select like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select a.*, b.othervar, b.somethingelse, b.thatvar&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which explicitly lists the variables from&amp;nbsp;B that you want that are not already in A&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will find SQL users that &lt;STRONG&gt;never &lt;/STRONG&gt;use the * for selection because it indicates that you don't really know what you really want or need.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 22:00:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-left-join-on-multiple-variables-Warning-that-variables/m-p/609199#M17839</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-03T22:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - left join on multiple variables - Warning that variables already exist</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-left-join-on-multiple-variables-Warning-that-variables/m-p/720112#M27689</link>
      <description>&lt;P&gt;select variables in right dataset to avoid notes in log&lt;BR /&gt;PROC SQL;&lt;BR /&gt;Create table exxb as&lt;BR /&gt;Select a.* ,b.exstdtc,extpt,medgroup as medex from xba4 as a left join exxx as b&lt;BR /&gt;On a.usubjid = b.usubjid and a.visit=b.visit;&lt;BR /&gt;Quit;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 06:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-left-join-on-multiple-variables-Warning-that-variables/m-p/720112#M27689</guid>
      <dc:creator>kalyan1234</dc:creator>
      <dc:date>2021-02-18T06:23:00Z</dc:date>
    </item>
  </channel>
</rss>

