<?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 Defaulting Missing Values in a PROC SQL Left Join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626439#M184766</link>
    <description>&lt;P&gt;In a Left Join, I may have missing values that I would like to default to some specific string.&amp;nbsp; I can't seem to determine when the Right table is not contributing observations.&amp;nbsp; In the following code, I want a table that looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;k1 aa bb gg hh&lt;BR /&gt;k2 cc dd XX YY&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;====&amp;nbsp;&amp;nbsp; defaulted data since no k2 value in right table&amp;nbsp; &amp;nbsp;&lt;BR /&gt;k3 ee ff ii jj&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Reading posts from this community, I think I want to use the CASE WHEN DO END sequence of statements but I can't seem to code them correctly - or if my test of IS NULL is correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data file1;
input 	key1 $
	var1 $
	var2 $;
datalines;
k1 aa bb
k2 cc dd
k3 ee ff
;

data file2;
input 	key2 $
	var3 $
	var4 $;
datalines;
k1 gg hh
k3 ii jj
; &lt;BR /&gt;
proc sql ;
     create table file3 as
	select  a.key1,
		a.var1,
		a.var2,
		b.var3,
		b.var4	
	case when b.key2 is null then 
	do ;
	        b.var3 = 'XX' ;
		b.var4 = 'YY' ;
	end ; 
	from file1 as A left join
	     file2 as B
	on   a.key1 = b.key2 ; &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 21 Feb 2020 11:27:14 GMT</pubDate>
    <dc:creator>jonthiele</dc:creator>
    <dc:date>2020-02-21T11:27:14Z</dc:date>
    <item>
      <title>Defaulting Missing Values in a PROC SQL Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626439#M184766</link>
      <description>&lt;P&gt;In a Left Join, I may have missing values that I would like to default to some specific string.&amp;nbsp; I can't seem to determine when the Right table is not contributing observations.&amp;nbsp; In the following code, I want a table that looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;k1 aa bb gg hh&lt;BR /&gt;k2 cc dd XX YY&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;====&amp;nbsp;&amp;nbsp; defaulted data since no k2 value in right table&amp;nbsp; &amp;nbsp;&lt;BR /&gt;k3 ee ff ii jj&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Reading posts from this community, I think I want to use the CASE WHEN DO END sequence of statements but I can't seem to code them correctly - or if my test of IS NULL is correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data file1;
input 	key1 $
	var1 $
	var2 $;
datalines;
k1 aa bb
k2 cc dd
k3 ee ff
;

data file2;
input 	key2 $
	var3 $
	var4 $;
datalines;
k1 gg hh
k3 ii jj
; &lt;BR /&gt;
proc sql ;
     create table file3 as
	select  a.key1,
		a.var1,
		a.var2,
		b.var3,
		b.var4	
	case when b.key2 is null then 
	do ;
	        b.var3 = 'XX' ;
		b.var4 = 'YY' ;
	end ; 
	from file1 as A left join
	     file2 as B
	on   a.key1 = b.key2 ; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Feb 2020 11:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626439#M184766</guid>
      <dc:creator>jonthiele</dc:creator>
      <dc:date>2020-02-21T11:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: Defaulting Missing Values in a PROC SQL Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626442#M184767</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281699"&gt;@jonthiele&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this code meet your expectations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
    create table file3 as
	select  a.key1,
		a.var1,
		a.var2,
		case when b.key2 is null then 'XX'
		     else b.var3
		     end as var3,
		case when b.key2 is null then 'YY'
		     else b.var4
		     end as var4
	from file1 as a left join
	     file2 as b
	on   a.key1 = b.key2 ; 
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Feb 2020 11:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626442#M184767</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-21T11:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: Defaulting Missing Values in a PROC SQL Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626443#M184768</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
     create table file3 as
	select  
    a.key1,
		a.var1,
		a.var2, 
    case when b.key2 is null then 'XX' else b.var3 end as va3,
    case when b.key2 is null then 'YY' else b.var4 end as va4


	from file1 as A left join
	     file2 as B
	on   a.key1 = b.key2 ; 

  quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 11:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626443#M184768</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-02-21T11:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: Defaulting Missing Values in a PROC SQL Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626445#M184770</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for this quick reply and solution!!!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 12:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626445#M184770</guid>
      <dc:creator>jonthiele</dc:creator>
      <dc:date>2020-02-21T12:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: Defaulting Missing Values in a PROC SQL Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626446#M184771</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This looks good as well.&amp;nbsp; &amp;nbsp;Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 12:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626446#M184771</guid>
      <dc:creator>jonthiele</dc:creator>
      <dc:date>2020-02-21T12:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Defaulting Missing Values in a PROC SQL Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626454#M184777</link>
      <description>&lt;P&gt;CoalesceC -function (for char values) is perfect for joins like this. Coalesce is for Num values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select f1.Key1,&lt;BR /&gt;F1.Var1,&lt;BR /&gt;F1.Var2,&lt;BR /&gt;Coalescec(F2.Var3,'XX') as Var3,&lt;BR /&gt;Coalescec(F2.Var4,'YY') as Var4&lt;BR /&gt;from File1 F1&lt;BR /&gt;left join File2 f2&lt;BR /&gt;on F1.Key1 = F2.Key2;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 13:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626454#M184777</guid>
      <dc:creator>Aku</dc:creator>
      <dc:date>2020-02-21T13:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Defaulting Missing Values in a PROC SQL Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626457#M184780</link>
      <description>&lt;P&gt;Note that in SQL code the SQL defined COALESCE() function is used.&amp;nbsp; So one function can be used for both numeric and character values.&amp;nbsp; &amp;nbsp;It is just in non-SQL code that you need to use COALESCEC(). Although you can use the SAS specific COALESCEC() function if you want, just like you can use any other SAS function.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 13:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defaulting-Missing-Values-in-a-PROC-SQL-Left-Join/m-p/626457#M184780</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-21T13:54:11Z</dc:date>
    </item>
  </channel>
</rss>

