<?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 Proc sql: replace null values from join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-replace-null-values-from-join/m-p/846035#M334469</link>
    <description>&lt;P&gt;I'm joining two tables. Within my joined table, a particular field has a null value that I'd like to replace with a non-null value. I'm wondering how I can accomplish this within one sql procedure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the below reprex, I create a table that has a null value for id: 3 in the sales field. I'm trying to replace this null value with something like calls*0.1. The only way I know how to do this would be with a case statement in a separate sql procedure ... wondering how I can do this all in one procedure. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*create sample table a*/&lt;BR /&gt;data table_a;
input id region $ calls;
cards;
1 south 50
2 north 30
3 west 30
4 south 50
;
run;
&lt;BR /&gt;/*create sample table b*/
data table_b;
input id sales;
cards;
1 5
3 4
4 6
;
run;
&lt;BR /&gt;/*join tables a &amp;amp; b*/
proc sql;
create table reprex as
select * 
from table_a as a 
left join table_b as b
on a.id = b.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Nov 2022 21:11:57 GMT</pubDate>
    <dc:creator>everyone</dc:creator>
    <dc:date>2022-11-23T21:11:57Z</dc:date>
    <item>
      <title>Proc sql: replace null values from join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-replace-null-values-from-join/m-p/846035#M334469</link>
      <description>&lt;P&gt;I'm joining two tables. Within my joined table, a particular field has a null value that I'd like to replace with a non-null value. I'm wondering how I can accomplish this within one sql procedure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the below reprex, I create a table that has a null value for id: 3 in the sales field. I'm trying to replace this null value with something like calls*0.1. The only way I know how to do this would be with a case statement in a separate sql procedure ... wondering how I can do this all in one procedure. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*create sample table a*/&lt;BR /&gt;data table_a;
input id region $ calls;
cards;
1 south 50
2 north 30
3 west 30
4 south 50
;
run;
&lt;BR /&gt;/*create sample table b*/
data table_b;
input id sales;
cards;
1 5
3 4
4 6
;
run;
&lt;BR /&gt;/*join tables a &amp;amp; b*/
proc sql;
create table reprex as
select * 
from table_a as a 
left join table_b as b
on a.id = b.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 21:11:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-replace-null-values-from-join/m-p/846035#M334469</guid>
      <dc:creator>everyone</dc:creator>
      <dc:date>2022-11-23T21:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql: replace null values from join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-replace-null-values-from-join/m-p/846038#M334470</link>
      <description>&lt;P&gt;Just do not use the * short cut.&amp;nbsp; Instead actually list the variables you want to select.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table reprex as
select a.id
     , a.region
     , a.calls
    , coalesce(b.sales,a.calls*0.10) as sales 
from table_a as a 
left join table_b as b
  on a.id = b.id
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2022 21:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-replace-null-values-from-join/m-p/846038#M334470</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-23T21:17:47Z</dc:date>
    </item>
  </channel>
</rss>

