<?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: problem with proc sql full join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/problem-with-proc-sql-full-join/m-p/367390#M275356</link>
    <description>&lt;P&gt;I think the below is what you're trying to do. See the "coalesce(..." added to the join conditions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table temp.balancedlongitudinal4POP  as
      select coalesce (a.DESY_SORT_KEY,b.DESY_SORT_KEY, c.DESY_SORT_KEY, d.DESY_SORT_KEY) as DESY_SORT_KEY,
	         coalesce (a.year,b.year, c.year, d.year)as LongitudinalYear,
             coalesce (a.PSG, 0)as PSG, coalesce(a.year_PSGtesting,.)as year_PSGtesting,
             coalesce (b.OSA_diag,0)as OSA_diag, coalesce(b.year_OSAdiagtesting,.) as year_OSAdiagtesting,
			 coalesce (c.PAPInit, 0) as PAP_Init, coalesce(c.year_PAPInit,.) as year_PAPInit,
			 coalesce (d.PAP_Comp, 0)as PAP_Comp
         from temp.longPsgNodup as a 
		 full join temp.longOSADiagNodup as b
	     on a.DESY_SORT_KEY=b.DESY_SORT_KEY and a.year=b.year
		 full join temp.longPapinitNodup as c
	     on coalesce(a.DESY_SORT_KEY, b.DESY_SORT_KEY) =c.DESY_SORT_KEY and 
		    coalesce(a.year, b.year)=c.year
		 full join temp.longPapCompNodup as d
		 on coalesce(a.DESY_SORT_KEY, b.DESY_SORT_KEY, c.DESY_SORT_KEY) = d.DESY_SORT_KEY and 
		    coalesce(a.year, b.year, c.year) = d.year;
                        
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 15 Jun 2017 14:37:54 GMT</pubDate>
    <dc:creator>collinelliot</dc:creator>
    <dc:date>2017-06-15T14:37:54Z</dc:date>
    <item>
      <title>problem with proc sql full join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-proc-sql-full-join/m-p/367374#M275355</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem doing mulptile talbes full join correctly. I'm hoping someone could help me point out what cause the error in my final joined table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have four datasets, each row has id (DESY_SORT_KEY), a dichomas variable on condition of interest, year of treatment/diagnosis, and a year variable with value of 2011/2012/2013. So in each of the longitudinal dataset, each id has three rows indicating yearly data (2011-2013). The four have datasets have overlapping ids but not exactly the same. In the final want dataset, i want to have all the ids from the four&amp;nbsp;have datasets and the combined&amp;nbsp;information by two link variables:DESY_SORT_KEY and longitudinalYear. My final dataset using the code below generates duplicate id and year combo because i'm joining the tables incorrectly. FYI, I checked back with my four original datasets. There are no duplicate id and year comobo. I'm hoping someone could help point out what went wrong with my code. Thank you for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table temp.balancedlongitudinal4POP  as
      select coalesce (a.DESY_SORT_KEY,b.DESY_SORT_KEY, c.DESY_SORT_KEY, d.DESY_SORT_KEY) as DESY_SORT_KEY,
	         coalesce (a.year,b.year, c.year, d.year)as LongitudinalYear,
             coalesce (a.PSG, 0)as PSG, coalesce(a.year_PSGtesting,.)as year_PSGtesting,
             coalesce (b.OSA_diag,0)as OSA_diag, coalesce(b.year_OSAdiagtesting,.) as year_OSAdiagtesting,
			 coalesce (c.PAPInit, 0) as PAP_Init, coalesce(c.year_PAPInit,.) as year_PAPInit,
			 coalesce (d.PAP_Comp, 0)as PAP_Comp
         from temp.longPsgNodup as a full join temp.longOSADiagNodup as b
	        on a.DESY_SORT_KEY=b.DESY_SORT_KEY and a.year=b.year
		      full join temp.longPapinitNodup as c
			   	on b.DESY_SORT_KEY=c.DESY_SORT_KEY and b.year=c.year
                   full join temp.longPapCompNodup as d
			          on c.DESY_SORT_KEY=d.DESY_SORT_KEY and c.year=d.year
                        ;
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Jun 2017 14:07:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-proc-sql-full-join/m-p/367374#M275355</guid>
      <dc:creator>Crystal_F</dc:creator>
      <dc:date>2017-06-15T14:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: problem with proc sql full join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-proc-sql-full-join/m-p/367390#M275356</link>
      <description>&lt;P&gt;I think the below is what you're trying to do. See the "coalesce(..." added to the join conditions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table temp.balancedlongitudinal4POP  as
      select coalesce (a.DESY_SORT_KEY,b.DESY_SORT_KEY, c.DESY_SORT_KEY, d.DESY_SORT_KEY) as DESY_SORT_KEY,
	         coalesce (a.year,b.year, c.year, d.year)as LongitudinalYear,
             coalesce (a.PSG, 0)as PSG, coalesce(a.year_PSGtesting,.)as year_PSGtesting,
             coalesce (b.OSA_diag,0)as OSA_diag, coalesce(b.year_OSAdiagtesting,.) as year_OSAdiagtesting,
			 coalesce (c.PAPInit, 0) as PAP_Init, coalesce(c.year_PAPInit,.) as year_PAPInit,
			 coalesce (d.PAP_Comp, 0)as PAP_Comp
         from temp.longPsgNodup as a 
		 full join temp.longOSADiagNodup as b
	     on a.DESY_SORT_KEY=b.DESY_SORT_KEY and a.year=b.year
		 full join temp.longPapinitNodup as c
	     on coalesce(a.DESY_SORT_KEY, b.DESY_SORT_KEY) =c.DESY_SORT_KEY and 
		    coalesce(a.year, b.year)=c.year
		 full join temp.longPapCompNodup as d
		 on coalesce(a.DESY_SORT_KEY, b.DESY_SORT_KEY, c.DESY_SORT_KEY) = d.DESY_SORT_KEY and 
		    coalesce(a.year, b.year, c.year) = d.year;
                        
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Jun 2017 14:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-proc-sql-full-join/m-p/367390#M275356</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2017-06-15T14:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: problem with proc sql full join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-proc-sql-full-join/m-p/367396#M275357</link>
      <description>That's super super helpful!!! Thanks a lot. I think now it works!</description>
      <pubDate>Thu, 15 Jun 2017 14:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-proc-sql-full-join/m-p/367396#M275357</guid>
      <dc:creator>Crystal_F</dc:creator>
      <dc:date>2017-06-15T14:51:36Z</dc:date>
    </item>
  </channel>
</rss>

