<?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: When I perform a left/right outer join in PROC SQL, I seem to be losing information in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/When-I-perform-a-left-right-outer-join-in-PROC-SQL-I-seem-to-be/m-p/774940#M246330</link>
    <description>&lt;P&gt;Yes, that works. I'm assuming that when I type&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select *&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select a.*, b.*&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it is showing the first instance of each variable in the case of ambiguity? That makes sense.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Oct 2021 17:25:50 GMT</pubDate>
    <dc:creator>fpb1</dc:creator>
    <dc:date>2021-10-18T17:25:50Z</dc:date>
    <item>
      <title>When I perform a left/right outer join in PROC SQL, I seem to be losing information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-I-perform-a-left-right-outer-join-in-PROC-SQL-I-seem-to-be/m-p/774926#M246323</link>
      <description>&lt;P&gt;Specifically, in data set C I am expecting the value of type in observation 7 to be X, not missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;```&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;data a; 
input model type $ price;
datalines; 
1 W 84
2 R 143
3 R 113
4 W 74
5 W 76
6 C 93
;

data b;
input type $ discount;
datalines;
C .25
R .3
W .2
X .5
;
run;

PROC SQL;
CREATE TABLE C AS
SELECT *
FROM A RIGHT JOIN B
ON A.type=B.type;
QUIT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 16:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-I-perform-a-left-right-outer-join-in-PROC-SQL-I-seem-to-be/m-p/774926#M246323</guid>
      <dc:creator>fpb1</dc:creator>
      <dc:date>2021-10-18T16:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: When I perform a left/right outer join in PROC SQL, I seem to be losing information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-I-perform-a-left-right-outer-join-in-PROC-SQL-I-seem-to-be/m-p/774930#M246324</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/392815"&gt;@fpb1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Specifically, in data set C I am expecting the value of type in observation 7 to be X, not missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;```&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;data a; 
input model type $ price;
datalines; 
1 W 84
2 R 143
3 R 113
4 W 74
5 W 76
6 C 93
;

data b;
input type $ discount;
datalines;
C .25
R .3
W .2
X .5
;
run;

PROC SQL;
CREATE TABLE C AS
SELECT *
FROM A RIGHT JOIN B
ON A.type=B.type;
QUIT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Best would be to provide an example of what you want for the output. Note that depending on who runs the code row "7" could have different values entirely.&lt;/P&gt;
&lt;P&gt;With your code example I get this in the log:&lt;/P&gt;
&lt;PRE&gt;121  PROC SQL;
122  CREATE TABLE C AS
123  SELECT *
124  FROM A RIGHT JOIN B
125  ON A.type=B.type;
WARNING: Variable type already exists on file WORK.C.
NOTE: Table WORK.C created, with 7 rows and 4 columns.
&lt;/PRE&gt;
&lt;P&gt;which happens because BOTH data sets have a variable Type and you have not specified which data set you want the value from for the variable Type (for which rows). So typically first set with the variable provides the values, in this set A.&lt;/P&gt;
&lt;P&gt;Also since you are requiring a match on type there is none for Type=X in data set B.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you are looking for something more like:&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
CREATE TABLE C AS
SELECT coalescec(a.type,b.type) as type, price, discount
FROM A RIGHT JOIN B
ON A.type=B.type;
QUIT;
&lt;/PRE&gt;
&lt;P&gt;The coalesecec (and for numeric values, coalesce) returns the first value in the list. So in this case when a.type is missing it looks for b.type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Serious concern at the validity of the join if you have multiple Type values without matches though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 17:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-I-perform-a-left-right-outer-join-in-PROC-SQL-I-seem-to-be/m-p/774930#M246324</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-18T17:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: When I perform a left/right outer join in PROC SQL, I seem to be losing information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-I-perform-a-left-right-outer-join-in-PROC-SQL-I-seem-to-be/m-p/774933#M246326</link>
      <description>&lt;P&gt;Try running it as&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE C AS
SELECT b.*, a.*
FROM A RIGHT JOIN B
ON A.type=B.type;
QUIT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and see if that isn't more what you thought you would get.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 17:12:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-I-perform-a-left-right-outer-join-in-PROC-SQL-I-seem-to-be/m-p/774933#M246326</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2021-10-18T17:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: When I perform a left/right outer join in PROC SQL, I seem to be losing information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-I-perform-a-left-right-outer-join-in-PROC-SQL-I-seem-to-be/m-p/774940#M246330</link>
      <description>&lt;P&gt;Yes, that works. I'm assuming that when I type&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select *&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select a.*, b.*&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it is showing the first instance of each variable in the case of ambiguity? That makes sense.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 17:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-I-perform-a-left-right-outer-join-in-PROC-SQL-I-seem-to-be/m-p/774940#M246330</guid>
      <dc:creator>fpb1</dc:creator>
      <dc:date>2021-10-18T17:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: When I perform a left/right outer join in PROC SQL, I seem to be losing information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-I-perform-a-left-right-outer-join-in-PROC-SQL-I-seem-to-be/m-p/774943#M246332</link>
      <description>&lt;P&gt;Thank you. This is a situation I encounter every day, though: demographic information in one table, medical test results in others, not every person has had every medical test so there are lots of non-matches.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 17:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-I-perform-a-left-right-outer-join-in-PROC-SQL-I-seem-to-be/m-p/774943#M246332</guid>
      <dc:creator>fpb1</dc:creator>
      <dc:date>2021-10-18T17:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: When I perform a left/right outer join in PROC SQL, I seem to be losing information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-I-perform-a-left-right-outer-join-in-PROC-SQL-I-seem-to-be/m-p/774957#M246339</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/392815"&gt;@fpb1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you. This is a situation I encounter every day, though: demographic information in one table, medical test results in others, not every person has had every medical test so there are lots of non-matches.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you do not have a personal identifier then you are asking for trouble. The proper matching variable for any medical information should be unique personal identifier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't have unique personal identifiers go talk to whoever is providing the data as they are setting up a situation with serious medical and financial risks (as in lawsuits).&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 17:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-I-perform-a-left-right-outer-join-in-PROC-SQL-I-seem-to-be/m-p/774957#M246339</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-18T17:51:19Z</dc:date>
    </item>
  </channel>
</rss>

