<?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 in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/proc-sql/m-p/733349#M28566</link>
    <description>&lt;P&gt;When you do a Left Join or Right Join on values ALL of the records from the Left or Right data set are included and the additional variables if requested from the second set appear and where the ON is not matched you get missing values for the added variables.. The order of the data sets matters.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data one;
  input x y;
datalines;
1 2
2 4
3 6
;
data two;
  input x z;
datalines;
1 44
2 55
;

proc sql;
   create table example as
   select a.x, a.y, b.z
   from one as a
        left join
        two as b
        on a.x = b.x
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;run the code and you will see that there are 3 records in the Example data set because set One has 3 and is the base for the Left Join. The value of z is missing for one record because there was not a matching x in set Two.&lt;/P&gt;
&lt;P&gt;Basic Left/Right join behavior: ALL the records, unless an additional filter such as WHERE is applied, from the base set appear in the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you do a cartesian join, which this is:&lt;/P&gt;
&lt;P&gt;Have_1 as a, Have_2 as b, Have_3 as c&lt;/P&gt;
&lt;P&gt;Every record in A is crossed with every record in B, then the result is crossed with every record in C.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your "where" is not the same as ON because it is applied after all of the above combinations are made and reduces to only the "all match" on the common varible.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Apr 2021 14:42:36 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-04-13T14:42:36Z</dc:date>
    <item>
      <title>proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-sql/m-p/733254#M28548</link>
      <description>&lt;P&gt;My question is that: I want to merge 3 tables in proc sql&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1)&amp;nbsp;&lt;/STRONG&gt;The first code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;Create table want_1 as&lt;BR /&gt;select a.*, b.x&lt;BR /&gt;from Have_1 as a&lt;BR /&gt;left join&lt;BR /&gt;Have_2 as b on&lt;BR /&gt;a.column- var = b.column- var;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;Create table want_2 as&lt;BR /&gt;select a.*, b.y&lt;BR /&gt;from want_1 as a&lt;BR /&gt;left join&lt;BR /&gt;Have_3 as b on&lt;BR /&gt;a.column - var = b.column - var;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm merging first two datasets, then with this output I merged with the third one&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2)&amp;nbsp;&lt;/STRONG&gt;The second code is: (where I merged three dataset in a single query)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table Combo as&lt;/P&gt;&lt;P&gt;select a.*, b.x, c.y&lt;/P&gt;&lt;P&gt;from Have_1 as a, Have_2 as b, Have_3 as c&lt;/P&gt;&lt;P&gt;where a.column-var= b.column-var and b.column-var = c.column-var;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when i run 2 codes i got the outputs, but the only difference is i got variation in the observation count.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first code shows more observation compared to the second one.&lt;/P&gt;&lt;P&gt;can anyone check anything wrong in my both the codes??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;why the variation has occurred?&lt;/P&gt;&lt;P&gt;which one is correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;TIA&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Apr 2021 10:51:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-sql/m-p/733254#M28548</guid>
      <dc:creator>Pooja98</dc:creator>
      <dc:date>2021-04-13T10:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-sql/m-p/733257#M28551</link>
      <description>&lt;P&gt;Please post the complete logs of both codes, using this button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In which dataset is variable var contained?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It will help GREATLY if you post examples for the three datasets in usable form (data steps with datalines) to illustrate the issue. Use the "little running man" button (right next to the one indicated above) to post the codes.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Apr 2021 10:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-sql/m-p/733257#M28551</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-13T10:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-sql/m-p/733349#M28566</link>
      <description>&lt;P&gt;When you do a Left Join or Right Join on values ALL of the records from the Left or Right data set are included and the additional variables if requested from the second set appear and where the ON is not matched you get missing values for the added variables.. The order of the data sets matters.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data one;
  input x y;
datalines;
1 2
2 4
3 6
;
data two;
  input x z;
datalines;
1 44
2 55
;

proc sql;
   create table example as
   select a.x, a.y, b.z
   from one as a
        left join
        two as b
        on a.x = b.x
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;run the code and you will see that there are 3 records in the Example data set because set One has 3 and is the base for the Left Join. The value of z is missing for one record because there was not a matching x in set Two.&lt;/P&gt;
&lt;P&gt;Basic Left/Right join behavior: ALL the records, unless an additional filter such as WHERE is applied, from the base set appear in the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you do a cartesian join, which this is:&lt;/P&gt;
&lt;P&gt;Have_1 as a, Have_2 as b, Have_3 as c&lt;/P&gt;
&lt;P&gt;Every record in A is crossed with every record in B, then the result is crossed with every record in C.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your "where" is not the same as ON because it is applied after all of the above combinations are made and reduces to only the "all match" on the common varible.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Apr 2021 14:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-sql/m-p/733349#M28566</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-13T14:42:36Z</dc:date>
    </item>
  </channel>
</rss>

