Hi all,
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 >=1.
PROC SQL ;
CREATE TABLE graph_data as
SELECT
dtevent,
count(*) as totalnum
FROM latestcounts
GROUP BY dtevent
ORDER By dtevent ;
QUIT ;
proc sql noprint;
select min(dtevent) , max(dtevent) into :sdate,:edate from latestcounts;
quit;
data dateev;
do dtevent=&sdate to &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 ;
an other solution If you don t have proc timeseries
1- attribute min and max dtevent into 2 macro variable
2- create a serie of date between min & max date
3- left join with proc sql
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.
proc sql noprint;
select min(dtevent) , max(dtevent) into :sdate,:edate from latestcounts;
quit;
data dateev;
do dtevent=&sdate to &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 ;
an other solution If you don t have proc timeseries
1- attribute min and max dtevent into 2 macro variable
2- create a serie of date between min & max date
3- left join with proc sql
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.