<?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: Help with table displaying dates with zero counts in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-table-displaying-dates-with-zero-counts/m-p/640550#M190830</link>
    <description>Thank you! This worked perfectly!</description>
    <pubDate>Thu, 16 Apr 2020 20:33:40 GMT</pubDate>
    <dc:creator>Krysia24</dc:creator>
    <dc:date>2020-04-16T20:33:40Z</dc:date>
    <item>
      <title>Help with table displaying dates with zero counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-table-displaying-dates-with-zero-counts/m-p/640249#M190649</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to create a table where the count of something is displayed by day. I am interested in also displaying the days where the count was zero. Here's what I have, which obviously only yields dates where count for that day was &amp;gt;=1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL ;&lt;BR /&gt;CREATE TABLE graph_data as&lt;BR /&gt;SELECT&lt;BR /&gt;dtevent,&amp;nbsp;&lt;BR /&gt;count(*) as totalnum&lt;BR /&gt;FROM latestcounts&lt;BR /&gt;GROUP BY&amp;nbsp;dtevent&lt;BR /&gt;ORDER By dtevent ;&lt;BR /&gt;QUIT ;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 23:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-table-displaying-dates-with-zero-counts/m-p/640249#M190649</guid>
      <dc:creator>Krysia24</dc:creator>
      <dc:date>2020-04-15T23:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Help with table displaying dates with zero counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-table-displaying-dates-with-zero-counts/m-p/640254#M190653</link>
      <description>If the data isn't there you have to create it. For TIMESERIES data you can use PROC TIMESERIES to fill in the dates, or depending on the complexity you can define a dataset with all the possible dates and merge on that or develop a CLASSDATA that can be used with PROC TABULATE. &lt;BR /&gt;&lt;BR /&gt;I'd probably lean towards PROC TIMESERIES here. &lt;BR /&gt;&lt;BR /&gt;/*1 - Create data set with missing data*/&lt;BR /&gt;data ibm;&lt;BR /&gt;	set sashelp.stocks;&lt;BR /&gt;	where stock='IBM';&lt;BR /&gt;&lt;BR /&gt;	if month(date)=7 then&lt;BR /&gt;		delete;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sort data=ibm;&lt;BR /&gt;	by date;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/*2 - Fill in missing values - you need to know the start and end of your series*/&lt;BR /&gt;proc timeseries data=ibm out=ibm_no_missing;&lt;BR /&gt;	id date interval=month start='01Aug1986'd end='01Dec2005'd;&lt;BR /&gt;	var open;&lt;BR /&gt;run;</description>
      <pubDate>Thu, 16 Apr 2020 01:58:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-table-displaying-dates-with-zero-counts/m-p/640254#M190653</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-04-16T01:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help with table displaying dates with zero counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-table-displaying-dates-with-zero-counts/m-p/640272#M190663</link>
      <description>&lt;P&gt;Unfortunately proc timeseries writes warnings to the log - which is a great idea in other scenarios, but because we want the gaps to be filled i would not expect warnings telling me that the procedure did what i wanted it to do. After a quick glance in the docs i was not able to find an option to disable the warnings, but perhaps i have overlooked something.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 05:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-table-displaying-dates-with-zero-counts/m-p/640272#M190663</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-04-16T05:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: Help with table displaying dates with zero counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-table-displaying-dates-with-zero-counts/m-p/640476#M190789</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select min(dtevent) , max(dtevent) into :sdate,:edate from latestcounts;
quit;

data dateev;
do dtevent=&amp;amp;sdate to &amp;amp;edate;
output;
end;
run;

PROC SQL ;
CREATE TABLE graph_data as
SELECT
l.dtevent,case when r.totalnum=. then 0 else r.totalnum end as totalnum 
from dateev as L left join 
(SELECT
dtevent, count(*) as totalnum
FROM latestcounts
GROUP BY dtevent) as R
on L.dtevent = R.dtevent
;
QUIT ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: inherit; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 1.7142; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;an other solution&lt;/SPAN&gt; If you don t have proc timeseries&lt;/P&gt;
&lt;P&gt;1- attribute min and max dtevent into 2 macro variable&lt;/P&gt;
&lt;P&gt;2- create a serie of date between min &amp;amp; max date&lt;/P&gt;
&lt;P&gt;3- left join with proc sql&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 15:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-table-displaying-dates-with-zero-counts/m-p/640476#M190789</guid>
      <dc:creator>kelxxx</dc:creator>
      <dc:date>2020-04-16T15:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Help with table displaying dates with zero counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-table-displaying-dates-with-zero-counts/m-p/640550#M190830</link>
      <description>Thank you! This worked perfectly!</description>
      <pubDate>Thu, 16 Apr 2020 20:33:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-table-displaying-dates-with-zero-counts/m-p/640550#M190830</guid>
      <dc:creator>Krysia24</dc:creator>
      <dc:date>2020-04-16T20:33:40Z</dc:date>
    </item>
  </channel>
</rss>

