Hi, I wanted to count events on dates using count() in proc sql. Here is the sample code: data have0;
infile cards truncover expandtabs;
input ID $ CODE DATE :date9. DEPT $ ;
format date date8. ;
cards;
A0001 7001 12Oct2015 ETA
A0001 7002 12Oct2015 ETA
A0001 7001 12Nov2015 ETA
A0001 7001 15Nov2016 ETA
A0001 7002 13Oct2016 ETB
A0001 7003 13Oct2015 ETB
A0002 7001 12Oct2015 ETA
A0002 7002 12Oct2015 ETA
A0002 7003 12Oct2015 ETA
A0002 7001 20Oct2016 ETB
A0002 7002 23Oct2016 ETB
A0002 7003 30Nov2016 ETB
;
run;
PROC SQL;
CREATE TABLE events_ct AS
SELECT
count(*) as line_cnt
,count(distinct ID) as ID_cnt
,count(distinct CODE) as CODE_cnt
,count(distinct case when DEPT="ETA" then CODE end) as EtA_CODE_cnt
,count(case when DEPT="ETA" then DATE end) as events_cnt
FROM have0
;
QUIT; The results for events_cnt shoud be 3 because I want to count the total distinct dates for each ID. What I need actually is something like this: count(distinct case when DEPT="ETA" then (DATE from have0 group by ID) end) as events_cnt but this code doesn't work as it is now. It there any solution to modify the count(case when DEPT="ETA" then DATE end) as events_cnt and get what I need? Thanks a lot !
... View more