<?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: PROC SQL not counting non existent entries in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-not-counting-non-existent-entries/m-p/697787#M213315</link>
    <description>&lt;P&gt;If you ever need to do this counting with SQL, here is a way to do it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WANT AS 
SELECT
	y.YEAR, 	
	s.STATE, 	
	m.MODE, 
	count(h.MODE) AS VALUE 
FROM 
	(select unique year from HAVE) as y cross join
	(select unique state from HAVE) as s cross join
	(select unique mode from HAVE) as m natural left join
	HAVE as h
GROUP BY y.YEAR, s.STATE, m.MODE; 
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
    <pubDate>Tue, 10 Nov 2020 02:37:36 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2020-11-10T02:37:36Z</dc:date>
    <item>
      <title>PROC SQL not counting non existent entries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-not-counting-non-existent-entries/m-p/697759#M213299</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am required to report incidents of X by year, state, mode of transport.&lt;/P&gt;&lt;P&gt;I have a decade worth of data and I used proc sql to count the incidents by mode of transport.&lt;/P&gt;&lt;P&gt;The problem is that I get no 0 counts, so I have some missing rows for some year+state+mode combinations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I fix this issue? I want to have all years and all states and all modes showing with 0s as the count, but the 0 count rows just don't appear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WANT AS SELECT&lt;BR /&gt;YEAR, STATE, MODE, count(MODE) AS VALUE FROM HAVE&lt;BR /&gt;GROUP BY YEAR, STATE, MODE; QUIT;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 22:27:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-not-counting-non-existent-entries/m-p/697759#M213299</guid>
      <dc:creator>K_S</dc:creator>
      <dc:date>2020-11-09T22:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL not counting non existent entries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-not-counting-non-existent-entries/m-p/697761#M213300</link>
      <description>So you want to count something that doesn't exist in your data?&lt;BR /&gt;That's not possible, within SQL especially. &lt;BR /&gt;&lt;BR /&gt;However, PROC FREQ has the SPARSE option which likely provides what you need - which is all combinations.&lt;BR /&gt;&lt;BR /&gt;proc freq data=have noprint;&lt;BR /&gt;table year*state*mode / out=want sparse;&lt;BR /&gt;run;</description>
      <pubDate>Mon, 09 Nov 2020 22:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-not-counting-non-existent-entries/m-p/697761#M213300</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-11-09T22:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL not counting non existent entriesI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-not-counting-non-existent-entries/m-p/697762#M213301</link>
      <description>&lt;P&gt;I think I really overcomplicated this!&lt;/P&gt;&lt;P&gt;No need to use proc sql here.&amp;nbsp; proc freq does a wonderful job...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 22:42:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-not-counting-non-existent-entries/m-p/697762#M213301</guid>
      <dc:creator>K_S</dc:creator>
      <dc:date>2020-11-09T22:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL not counting non existent entries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-not-counting-non-existent-entries/m-p/697787#M213315</link>
      <description>&lt;P&gt;If you ever need to do this counting with SQL, here is a way to do it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WANT AS 
SELECT
	y.YEAR, 	
	s.STATE, 	
	m.MODE, 
	count(h.MODE) AS VALUE 
FROM 
	(select unique year from HAVE) as y cross join
	(select unique state from HAVE) as s cross join
	(select unique mode from HAVE) as m natural left join
	HAVE as h
GROUP BY y.YEAR, s.STATE, m.MODE; 
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 02:37:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-not-counting-non-existent-entries/m-p/697787#M213315</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-11-10T02:37:36Z</dc:date>
    </item>
  </channel>
</rss>

