<?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 How to include zero frequencies (proc sql, proc freq) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-include-zero-frequencies-proc-sql-proc-freq/m-p/847589#M335102</link>
    <description>&lt;P&gt;The following proc sql will allow to have a zero frequency for females aged 16.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table cnt as   
        select distinct sex, age, count(*) as cnt
        from sashelp.class
        group by sex, age;
    
    create table ref as 
        select distinct a.sex, b.age, 0 as cnt
        from sashelp.class a, sashelp.class b;
    
    create table sex_age_cnt as
        select a.sex, a.age, coalesce(b.cnt,a.cnt) as cnt
        from ref a
        left join 
             cnt b
        on a.sex=b.sex and
           a.age=b.age;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc_sql_zero_frequency.JPG" style="width: 108px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77975iA2FDC4A2CE42907E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="proc_sql_zero_frequency.JPG" alt="proc_sql_zero_frequency.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I can also get the result using proc means.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=sashelp.class completetypes;
    class sex age;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there any smarter way to get the same result using proc sql/proc freq?&lt;/P&gt;</description>
    <pubDate>Sat, 03 Dec 2022 19:03:56 GMT</pubDate>
    <dc:creator>xxformat_com</dc:creator>
    <dc:date>2022-12-03T19:03:56Z</dc:date>
    <item>
      <title>How to include zero frequencies (proc sql, proc freq)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-include-zero-frequencies-proc-sql-proc-freq/m-p/847589#M335102</link>
      <description>&lt;P&gt;The following proc sql will allow to have a zero frequency for females aged 16.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table cnt as   
        select distinct sex, age, count(*) as cnt
        from sashelp.class
        group by sex, age;
    
    create table ref as 
        select distinct a.sex, b.age, 0 as cnt
        from sashelp.class a, sashelp.class b;
    
    create table sex_age_cnt as
        select a.sex, a.age, coalesce(b.cnt,a.cnt) as cnt
        from ref a
        left join 
             cnt b
        on a.sex=b.sex and
           a.age=b.age;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc_sql_zero_frequency.JPG" style="width: 108px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77975iA2FDC4A2CE42907E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="proc_sql_zero_frequency.JPG" alt="proc_sql_zero_frequency.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I can also get the result using proc means.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=sashelp.class completetypes;
    class sex age;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there any smarter way to get the same result using proc sql/proc freq?&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2022 19:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-include-zero-frequencies-proc-sql-proc-freq/m-p/847589#M335102</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2022-12-03T19:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to include zero frequencies (proc sql, proc freq)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-include-zero-frequencies-proc-sql-proc-freq/m-p/847615#M335113</link>
      <description>&lt;P&gt;PROC FREQ with the SPARSE option&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=sashelp.class;
tables sex*age / sparse list out=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is shorter than PROC SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want2 as
select sex, age, count(a.sex) as cnt from 
(select distinct b.sex, c.age from sashelp.class b, sashelp.class c)
natural left join
sashelp.class a
group by 1,2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Dec 2022 00:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-include-zero-frequencies-proc-sql-proc-freq/m-p/847615#M335113</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-12-04T00:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to include zero frequencies (proc sql, proc freq)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-include-zero-frequencies-proc-sql-proc-freq/m-p/847629#M335119</link>
      <description>&lt;P&gt;Thanks. I forgot about the *.&lt;/P&gt;
&lt;P&gt;For those reading this post, notice that with ods output, the sparse option is not needed.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Dec 2022 09:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-include-zero-frequencies-proc-sql-proc-freq/m-p/847629#M335119</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2022-12-04T09:24:46Z</dc:date>
    </item>
  </channel>
</rss>

