@d6k5d3 Here I am re-posting it
data have;
input (Date Time Ask Bid Day Price Return) ($);
cards;
xxx xxx xxx xxx Mon xxx xxxx
xxx xxx xxx xxx Mon xxx 0
xxx xxx xxx xxx Mon xxx 0
xxx xxx xxx xxx Mon xxx xxxx
xxx xxx xxx xxx Mon xxx xxxx
xxx xxx xxx xxx Mon xxx 0
xxx xxx xxx xxx Mon xxx 0
xxx xxx xxx xxx Mon xxx 0
xxx xxx xxx xxx Tue xxx 0
xxx xxx xxx xxx Tue xxx 0
xxx xxx xxx xxx Tue xxx 0
xxx xxx xxx xxx Tue xxx xxxx
xxx xxx xxx xxx Tue xxx xxxx
xxx xxx xxx xxx Tue xxx 0
xxx xxx xxx xxx Tue xxx xxxx
xxx xxx xxx xxx Tue xxx 0
xxx xxx xxx xxx Wed xxx xxxx
xxx xxx xxx xxx Wed xxx 0
xxx xxx xxx xxx Wed xxx 0
xxx xxx xxx xxx Wed xxx xxxx
xxx xxx xxx xxx Wed xxx xxxx
xxx xxx xxx xxx Wed xxx 0
xxx xxx xxx xxx Wed xxx 0
xxx xxx xxx xxx Wed xxx 0
xxx xxx xxx xxx Wed xxx xxxx
xxx xxx xxx xxx Wed xxx xxxx
xxx xxx xxx xxx Wed xxx xxxx
xxx xxx xxx xxx Wed xxx xxxx
;
data grp;
set have;
by day return notsorted;
if first.day then Incid_of_consec0s =0;
if first.return and return='0' then Incid_of_consec0s+1;
if return='0';
run;
proc sql;
create table want as
select day,Incid_of_consec0s,sum(return='0') as zero_count_in_each_incid
from grp
group by day,Incid_of_consec0s;
quit;
No worries 🙂
sorry that I may have not interpreted @d6k5d3 I would like to know for the same day how many returns are 0s statement.
You should have said something about date in your original request so that the your requested was fully stated.
data have;
input (Date Time Ask Bid Day Price Return) ($);
cards;
xxx xxx xxx xxx Mon xxx xxxx
xxx xxx xxx xxx Mon xxx xxxx
xxx xxx xxx xxx Mon xxx xxxx
xxx xxx xxx xxx Tue xxx 0
xxx xxx xxx xxx Tue xxx 0
xxx xxx xxx xxx Tue xxx 0
xxx xxx xxx xxx Tue xxx 0
xxx xxx xxx xxx Wed xxx xxxx
xxx xxx xxx xxx Wed xxx 0
xxx xxx xxx xxx Wed xxx 0
;
proc sql;
create table want as
select day,sum(return='0') as zero_retun_count
from have
group by day;
quit;
data have;
input (Date Time Ask Bid Day Price Return) ($);
cards;
xxx xxx xxx xxx Mon xxx xxxx
xxx xxx xxx xxx Mon xxx xxxx
xxx xxx xxx xxx Mon xxx xxxx
xxx xxx xxx xxx Tue xxx 0
xxx xxx xxx xxx Tue xxx 0
xxx xxx xxx xxx Tue xxx 0
xxx xxx xxx xxx Tue xxx 0
xxx xxx xxx xxx Wed xxx xxxx
xxx xxx xxx xxx Wed xxx 0
xxx xxx xxx xxx Wed xxx 0
;
data want;
set have;
by day notsorted;
if first.day then count=0;
count +return='0';
if last.day ;
run;
After sifting through many messages, here is what I think you are looking for:
data want;
set have;
by date return notsorted;
if first.date then incident_no = 0;
if first.return then consecutive=1;
else consecutive + 1;
if last.return;
if return='0';
incident_no + 1;
run;
Thank you so very much for understanding me! This is what exactly I wanted! Hats off!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.