<?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 and Drop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580605#M164945</link>
    <description>Oh yes, thank you Reeza...I had forgotten about this option!</description>
    <pubDate>Mon, 12 Aug 2019 16:58:55 GMT</pubDate>
    <dc:creator>Xinxin</dc:creator>
    <dc:date>2019-08-12T16:58:55Z</dc:date>
    <item>
      <title>Proc Sql and Drop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580268#M164809</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I am joining 2 tables and this is my syntax:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table final1 as select a.*, b.* from main1 a left join main2 b&lt;BR /&gt;on a.ACCOUNT_ID = b.ACCOUNT_ID&lt;BR /&gt;;&amp;nbsp;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I know why I get the following note:&amp;nbsp;WARNING: Variable ACCOUNT_ID already exists on file WORK.FINAL1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both a and b data sets have many columns and I don't want to list out ALL the columns of b and just eliminate&amp;nbsp;ACCOUNT_ID.&lt;/P&gt;
&lt;P&gt;I tried using DROP at various places but did not work.&lt;/P&gt;
&lt;P&gt;What is the method with proc sql if you want to keep a lot more columns than you want to drop, when joining tables. (In this ex I want to drop only 1 but my query is in general)&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 20:36:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580268#M164809</guid>
      <dc:creator>Xinxin</dc:creator>
      <dc:date>2019-08-09T20:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql and Drop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580275#M164810</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/237"&gt;@Xinxin&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;It can be done by using a little rename/drop subterfuge:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;                                                    
  create table final1 &lt;FONT color="#800080"&gt;&lt;STRONG&gt;(drop=account_id2)&lt;/STRONG&gt;&lt;/FONT&gt; as                   
  select *                                                    
  from   main1 left join main2 &lt;FONT color="#800080"&gt;&lt;STRONG&gt;(rename=account_id=account_id2)&lt;/STRONG&gt;&lt;/FONT&gt;
  on     &lt;FONT color="#800080"&gt;&lt;STRONG&gt;account_id = account_id2&lt;/STRONG&gt; &lt;/FONT&gt;                            
  ;                                                           
quit ;                                                        
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Another advantage of this trick is that you don't even have to qualify the tables being joined - provided, of course, that table MAIN2 has no column named ACCOUNT_ID2. To be even more on the safe side, you can use something wild like ___AID instead of ACCOUNT_ID2 (use as many leading underscores as need be to ensure the column doesn't exist in the tables being joined).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AFAIK, with FedSQL in Viya, you can use the USING clause to achieve the effect without jumping through hoops like above:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;                                                    
  create table final1 (drop=account_id2) as                   
  select *                                                    
  from   main1 left join main2
  &lt;FONT color="#800080"&gt;&lt;STRONG&gt;using (account_id)&lt;/STRONG&gt;&lt;/FONT&gt;                             
  ;                                                           
quit ;     &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Documented at:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=casfedsql&amp;amp;docsetTarget=p1nh3lts36c17yn1og1qwpoiznvb.htm&amp;amp;docsetVersion=3.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=casfedsql&amp;amp;docsetTarget=p1nh3lts36c17yn1og1qwpoiznvb.htm&amp;amp;docsetVersion=3.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my 9.4 it doesn't work, though, so I use the rename/drop recipe to get what I want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 21:31:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580275#M164810</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-08-09T21:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql and Drop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580295#M164823</link>
      <description>&lt;P&gt;Since account_id is the only field in common, you can also do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;                                                    
  create table final1 as                   
  select *                                                    
  from main1 natural left join main2;             
  ;                                                           
quit ; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Aug 2019 22:49:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580295#M164823</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-08-09T22:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql and Drop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580305#M164827</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Egad! You've just dispelled my confusion that "natural" is applicable to inner joins only. Not that I haven't tried, but in my utter stupidity, I coded "left natural" rather than "natural left", having neglected to try it in the opposite order ... duh.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, compared to the rename/drop or using the USING clause, a natural join creates a program-control limitation by auto-joining on all the columns with the same names and data types. Methinks it would be best if the USING clause &lt;EM&gt;in this sense&lt;/EM&gt; were made applicable to all SAS SQL flavors. But I'm afraid there exists a serious obstacle, since though in Base the clause does exist, it is already used for a different purpose (related to working with external data bases).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 23:10:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580305#M164827</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-08-09T23:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql and Drop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580315#M164833</link>
      <description>&lt;P&gt;One other option, but not as succinct as the others one here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the FEEDBACK option on the PROC SQL and check the log. It will have the fully generated code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bmi;
set sashelp.class;

bmi = weight*703 / (height**2) ;

keep name bmi;
run;


proc sql FEEDBACK;
create table want as
select *
from sashelp.class as a
left join bmi as b
on a.name=b.name;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The FEEDBACK option puts this into the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; 78         proc sql FEEDBACK;
 79         create table want as
 80         select *
 81         from sashelp.class as a
 82         left join bmi as b
 83         on a.name=b.name;
 NOTE: Statement transforms to:
 
&lt;FONT size="4" color="#FF6600"&gt;&lt;STRONG&gt;         select A.Name, A.Sex, A.Age, A.Height, A.Weight, B.Name, B.bmi
           from SASHELP.CLASS A left outer join WORK.BMI B on A.Name = B.Name;
&lt;/STRONG&gt; &lt;/FONT&gt;
 WARNING: Variable Name already exists on file WORK.WANT.
 NOTE: Table WORK.WANT created, with 19 rows and 6 columns.&lt;/PRE&gt;
&lt;P&gt;You can easily filter the columns now.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Aug 2019 02:31:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580315#M164833</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-10T02:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql and Drop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580604#M164944</link>
      <description>Wow....genius! I can do this with multiple tables too! Thanks a lot!!&lt;BR /&gt;</description>
      <pubDate>Mon, 12 Aug 2019 16:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580604#M164944</guid>
      <dc:creator>Xinxin</dc:creator>
      <dc:date>2019-08-12T16:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql and Drop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580605#M164945</link>
      <description>Oh yes, thank you Reeza...I had forgotten about this option!</description>
      <pubDate>Mon, 12 Aug 2019 16:58:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580605#M164945</guid>
      <dc:creator>Xinxin</dc:creator>
      <dc:date>2019-08-12T16:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql and Drop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580607#M164946</link>
      <description>Thank you very much....this worked!</description>
      <pubDate>Mon, 12 Aug 2019 17:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-and-Drop/m-p/580607#M164946</guid>
      <dc:creator>Xinxin</dc:creator>
      <dc:date>2019-08-12T17:00:39Z</dc:date>
    </item>
  </channel>
</rss>

