<?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: Shorten the left join 4 files by using proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Shorten-the-left-join-4-files-by-using-proc-sql/m-p/720127#M223048</link>
    <description>&lt;P&gt;If you want to keep the order of a dataset while adding information from another (doing a "lookup"), the hash object is the tool of choice.&lt;/P&gt;</description>
    <pubDate>Thu, 18 Feb 2021 07:36:32 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-02-18T07:36:32Z</dc:date>
    <item>
      <title>Shorten the left join 4 files by using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Shorten-the-left-join-4-files-by-using-proc-sql/m-p/720098#M223037</link>
      <description>&lt;P&gt;Hi all SAS Users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want todo left join&amp;nbsp; the files&lt;STRONG&gt; industry_mtbv, industry_return,&amp;nbsp;herfindahl_final ( these three file have same order, same two columns INDC3 and YEAR )&lt;/STRONG&gt;&amp;nbsp;to the file &lt;STRONG&gt;winsorize&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;My novice code is as below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*******Match winso and industry_return****************/
libname winso 'C:\Users\pnguyen\Desktop\winso' access=readonly;
proc copy inlib=winso outlib=work mt=data;
run;

data _wins1 / view=_wins1;
set work.winsorize;
_seqno1=_n_;
run;

proc sql;
create table matching1(drop=_seqno1) as
select a.*, industry_ret
from _wins1 a left join work.industry_return b
on a.indc3 = b.indc3 and a.year=b.year
order by _seqno1;
drop view _wins1;
quit;

/******Match matching1 and industry_mtbv************/

data _wins2 / view=_wins2;
set work.matching1;
_seqno2=_n_;
run;

proc sql;
create table matching2(drop=_seqno2) as
select a.*, median_mtbv
from _wins2 a left join work.industry_mtbv b
on a.indc3 = b.indc3 and a.year=b.year
order by _seqno2;
drop view _wins2;
quit;

/******Match matching2 and herfindahl_final*******/

data _wins3 / view=_wins3;
set work.matching2;
_seqno3=_n_;
run;

proc sql;
create table matching3(drop=_seqno3) as
select a.*, Herfindahl
from _wins3 a left join work.herfindahl_final b
on a.indc3 = b.indc3 and a.year=b.year
order by _seqno3;
drop view _wins3;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I know it is long so is there any way to shorten this code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warmest regards.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 04:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Shorten-the-left-join-4-files-by-using-proc-sql/m-p/720098#M223037</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-02-18T04:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Shorten the left join 4 files by using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Shorten-the-left-join-4-files-by-using-proc-sql/m-p/720127#M223048</link>
      <description>&lt;P&gt;If you want to keep the order of a dataset while adding information from another (doing a "lookup"), the hash object is the tool of choice.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 07:36:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Shorten-the-left-join-4-files-by-using-proc-sql/m-p/720127#M223048</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-18T07:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: Shorten the left join 4 files by using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Shorten-the-left-join-4-files-by-using-proc-sql/m-p/720139#M223054</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If &lt;FONT face="courier new,courier"&gt;INDC3 Year&lt;/FONT&gt; is a unique key in each of the datasets &lt;FONT face="courier new,courier"&gt;industry_return&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;industry_mtbv&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;herfindahl_final&lt;/FONT&gt;, it should be no problem to combine all three left joins in a single PROC SQL step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _wins / view=_wins;
set winsorize;
_seqno=_n_;
run;

proc sql;
create table matching(drop=_seqno) as
select a.*, industry_ret, median_mtbv, Herfindahl
from _wins a
  left join industry_return b
    on a.indc3=b.indc3 and a.year=b.year
  left join industry_mtbv c
    on a.indc3=c.indc3 and a.year=c.year
  left join herfindahl_final d
    on a.indc3=d.indc3 and a.year=d.year
order by _seqno;
drop view _wins;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Feb 2021 09:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Shorten-the-left-join-4-files-by-using-proc-sql/m-p/720139#M223054</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-18T09:37:44Z</dc:date>
    </item>
  </channel>
</rss>

