<?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: Include not existing value to list of by group in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Include-not-existing-value-to-list-of-by-group-in-proc-sql/m-p/722313#M223948</link>
    <description>&lt;P&gt;You are on the right track, all you need is a left join:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data origins;
length _origin $10;
do _origin = "Asia", "Europe", "USA", "Australia";
    output;
    end;
run;

proc sql;
   create table sample as
   select 
        o._origin, 
        c.*, 
        coalesce(sum(MSRP), 0) as total_srp
   from 
        origins as o left join 
        sashelp.cars as c on o._origin = c.origin
   group by o._origin;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 27 Feb 2021 04:45:36 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2021-02-27T04:45:36Z</dc:date>
    <item>
      <title>Include not existing value to list of by group in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-not-existing-value-to-list-of-by-group-in-proc-sql/m-p/722307#M223945</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table for example sashelp.cars, and I want to group them by origin and total their MSRP.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question is, what if I want to add 'Australia' in the list of by group but in the sashelp.cars, there are no make/model that originated from Australia?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I did is to use proc sql:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
   create table sample as
      select *, sum(MSRP) as total_srp
   from sashelp.cars
   group by origin;
quit;&lt;/PRE&gt;&lt;P&gt;But in output dataset sample, I only see 'Asia' 'Europe' and 'USA' since they are the only one's available from sashelp.cars.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a more straightforward way to include Australia in the output dataset sample with 0 total_srp even though it's not existing before the by group?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm thinking is having a meta table with complete list of Origin:&amp;nbsp; 'Asia' 'Europe', 'USA" and "Australia" and then look-up into the sashelp.cars so that it will have a 'dummy' value before doing the proc sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 03:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-not-existing-value-to-list-of-by-group-in-proc-sql/m-p/722307#M223945</guid>
      <dc:creator>clemz</dc:creator>
      <dc:date>2021-02-27T03:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Include not existing value to list of by group in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-not-existing-value-to-list-of-by-group-in-proc-sql/m-p/722313#M223948</link>
      <description>&lt;P&gt;You are on the right track, all you need is a left join:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data origins;
length _origin $10;
do _origin = "Asia", "Europe", "USA", "Australia";
    output;
    end;
run;

proc sql;
   create table sample as
   select 
        o._origin, 
        c.*, 
        coalesce(sum(MSRP), 0) as total_srp
   from 
        origins as o left join 
        sashelp.cars as c on o._origin = c.origin
   group by o._origin;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 04:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-not-existing-value-to-list-of-by-group-in-proc-sql/m-p/722313#M223948</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-02-27T04:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Include not existing value to list of by group in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-not-existing-value-to-list-of-by-group-in-proc-sql/m-p/722316#M223950</link>
      <description>thanks for the tip. I just customized it so that I won't be renaming _origin. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Sat, 27 Feb 2021 05:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-not-existing-value-to-list-of-by-group-in-proc-sql/m-p/722316#M223950</guid>
      <dc:creator>clemz</dc:creator>
      <dc:date>2021-02-27T05:39:57Z</dc:date>
    </item>
  </channel>
</rss>

