<?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 proc sql - creating a table by left joining two datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-creating-a-table-by-left-joining-two-datasets/m-p/551649#M153289</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use proc sql to create a table and do a left join between two datasets - I have the following two lines to start off with so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table NEV_TIME_ON_BOOK as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Steps to be completed:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;1. Variables to select from datasets A and B:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Dataset&amp;nbsp;&lt;STRONG&gt;cdpview.card_2019&lt;/STRONG&gt; as &lt;U&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/U&gt; - select:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;account_ID&lt;/STRONG&gt;, &lt;STRONG&gt;month_end&lt;/STRONG&gt;, &lt;STRONG&gt;time_on_book&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset &lt;STRONG&gt;cdpview.output_2019&lt;/STRONG&gt; as &lt;U&gt;&lt;STRONG&gt;B&lt;/STRONG&gt; &lt;/U&gt;- select:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;account_ID&lt;/STRONG&gt;, &lt;STRONG&gt;month_end&lt;/STRONG&gt;, &lt;STRONG&gt;portfolio_segment&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;2. Left join&lt;/U&gt;&lt;/P&gt;&lt;P&gt;I would like to do a left join:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cdpview.card_2019 as A&lt;BR /&gt;left join cdpview.output_2019 as B&lt;BR /&gt;on a.account_id = B.account_id and a.mth_end = b.mth_end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;3. Only see results where portfolio_segment='NEV'&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Also, from dataset B (cdpview.output_2019), I would only want to see results where portfolio_segment='NEV'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there code so that once the left join has been done, the table NEV_TIME_ON_BOOK:&lt;/P&gt;&lt;P&gt;1. Lists the 'time_on_book' results for each of the records where&amp;nbsp;portfolio_segment='NEV'.&lt;/P&gt;&lt;P&gt;2. The table is ordered by account_ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Wed, 17 Apr 2019 11:25:39 GMT</pubDate>
    <dc:creator>jeremy4</dc:creator>
    <dc:date>2019-04-17T11:25:39Z</dc:date>
    <item>
      <title>proc sql - creating a table by left joining two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-creating-a-table-by-left-joining-two-datasets/m-p/551649#M153289</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use proc sql to create a table and do a left join between two datasets - I have the following two lines to start off with so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table NEV_TIME_ON_BOOK as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Steps to be completed:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;1. Variables to select from datasets A and B:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Dataset&amp;nbsp;&lt;STRONG&gt;cdpview.card_2019&lt;/STRONG&gt; as &lt;U&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/U&gt; - select:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;account_ID&lt;/STRONG&gt;, &lt;STRONG&gt;month_end&lt;/STRONG&gt;, &lt;STRONG&gt;time_on_book&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset &lt;STRONG&gt;cdpview.output_2019&lt;/STRONG&gt; as &lt;U&gt;&lt;STRONG&gt;B&lt;/STRONG&gt; &lt;/U&gt;- select:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;account_ID&lt;/STRONG&gt;, &lt;STRONG&gt;month_end&lt;/STRONG&gt;, &lt;STRONG&gt;portfolio_segment&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;2. Left join&lt;/U&gt;&lt;/P&gt;&lt;P&gt;I would like to do a left join:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cdpview.card_2019 as A&lt;BR /&gt;left join cdpview.output_2019 as B&lt;BR /&gt;on a.account_id = B.account_id and a.mth_end = b.mth_end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;3. Only see results where portfolio_segment='NEV'&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Also, from dataset B (cdpview.output_2019), I would only want to see results where portfolio_segment='NEV'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there code so that once the left join has been done, the table NEV_TIME_ON_BOOK:&lt;/P&gt;&lt;P&gt;1. Lists the 'time_on_book' results for each of the records where&amp;nbsp;portfolio_segment='NEV'.&lt;/P&gt;&lt;P&gt;2. The table is ordered by account_ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 11:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-creating-a-table-by-left-joining-two-datasets/m-p/551649#M153289</guid>
      <dc:creator>jeremy4</dc:creator>
      <dc:date>2019-04-17T11:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql - creating a table by left joining two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-creating-a-table-by-left-joining-two-datasets/m-p/551667#M153294</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have given all the elements. Putting them together gives :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table NEV_TIME_ON_BOOK as
    select a.account_ID, a.month_end, a.time_on_book, b.portfolio_segment
    from cdpview.card_2019 as a
    left join cdpview.output_2019 as b
    on a.account_id = b.account_id and a.month_end = b.month_end
    where b.portfolio_segment='NEV'
    order by a.account_ID
    ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I assumed mth_end was a typo for month_end.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 12:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-creating-a-table-by-left-joining-two-datasets/m-p/551667#M153294</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-04-17T12:13:35Z</dc:date>
    </item>
  </channel>
</rss>

