<?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: SQL NULL JOINs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-NULL-JOINs/m-p/586589#M167457</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/280733"&gt;@kenjichan1212&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I understood your problem correctly then below should do the job. What it does: Select from table1 all rows with a matching year in table2.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
  infile datalines truncover dlm=',';
  input year category:$20. admission;
  datalines;
2011,Category 1,0
2011,Category 2,0
2012,Category 1,0
2012,Category 2,0
2013,Category 1,0
2013,Category 2,20
;
run;

data table2;
  infile datalines truncover dlm=',';
  input year category:$20. admission;
  datalines;
2013,Category 2,20
;
run;

 
proc sql;
/*  create table want as*/
  select t1.*
  from table1 t1
  where exists
    (select * from table2 t2 where t2.year=t1.year)
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Sep 2019 01:48:48 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-09-06T01:48:48Z</dc:date>
    <item>
      <title>SQL NULL JOINs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-NULL-JOINs/m-p/586581#M167450</link>
      <description>&lt;P&gt;Hi I have two tables as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Year&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Category&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Admissions&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2011&amp;nbsp;&amp;nbsp;&amp;nbsp; Category 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2011&amp;nbsp;&amp;nbsp;&amp;nbsp; Category&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2012&amp;nbsp;&amp;nbsp;&amp;nbsp; Category 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2012&amp;nbsp;&amp;nbsp;&amp;nbsp; Category&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2013&amp;nbsp;&amp;nbsp;&amp;nbsp; Category 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2013&amp;nbsp;&amp;nbsp;&amp;nbsp; Category&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 20&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Year&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Category&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Admissions&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2013&amp;nbsp;&amp;nbsp;&amp;nbsp; Category&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 20&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I get a table looking as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2013&amp;nbsp;&amp;nbsp;&amp;nbsp; Category 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2013&amp;nbsp;&amp;nbsp;&amp;nbsp; Category&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 20&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried left joining them by Year but it gets rid of the zeros for 2013 Category 1. Sorry any help is appreciated&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2019 01:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-NULL-JOINs/m-p/586581#M167450</guid>
      <dc:creator>kenjichan1212</dc:creator>
      <dc:date>2019-09-06T01:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: SQL NULL JOINs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-NULL-JOINs/m-p/586587#M167455</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data table1;
input Year      Category &amp;amp; $15.    Admissions ;
cards;
2011    Category 1    0
2011    Category 2    0
2012    Category 1    0
2012    Category 2    0
2013    Category 1    0
2013    Category 2    20
;
 

data table2;
input Year      Category &amp;amp; $15.    Admissions ;
cards;
2013    Category 2    20
;

 
proc sql;
create table want as
select a.* ,b.admissions as table1_admissions
from table2 a left join table1 b
on a.year=b.year ;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Sep 2019 01:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-NULL-JOINs/m-p/586587#M167455</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-06T01:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: SQL NULL JOINs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-NULL-JOINs/m-p/586589#M167457</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/280733"&gt;@kenjichan1212&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I understood your problem correctly then below should do the job. What it does: Select from table1 all rows with a matching year in table2.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
  infile datalines truncover dlm=',';
  input year category:$20. admission;
  datalines;
2011,Category 1,0
2011,Category 2,0
2012,Category 1,0
2012,Category 2,0
2013,Category 1,0
2013,Category 2,20
;
run;

data table2;
  infile datalines truncover dlm=',';
  input year category:$20. admission;
  datalines;
2013,Category 2,20
;
run;

 
proc sql;
/*  create table want as*/
  select t1.*
  from table1 t1
  where exists
    (select * from table2 t2 where t2.year=t1.year)
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2019 01:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-NULL-JOINs/m-p/586589#M167457</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-09-06T01:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: SQL NULL JOINs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-NULL-JOINs/m-p/586591#M167458</link>
      <description>&lt;P&gt;Or, if you can afford to name all variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select 
	b.Year, 
	a.Category,
	a.Admissions
from table2 a left join table1 b
on a.year=b.year ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Sep 2019 01:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-NULL-JOINs/m-p/586591#M167458</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-09-06T01:29:10Z</dc:date>
    </item>
  </channel>
</rss>

