/* test data */
data zero;
input id date :yymmdd10. value;
format date e8601da.;
cards;
1 2011/01/01 0
1 2011/01/02 0
1 2011/01/03 1
1 2011/01/04 2
2 2011/01/01 1
2 2011/01/02 2
2 2011/01/03 3
2 2011/01/04 4
;
run;
proc sql;
/* sum of value between (date-1) and (date-3) for each date */
select zero.id, zero.date, sum(one.value) as sum3
from zero left join zero as one on zero.id = one.id and
one.date between zero.date-1 and zero.date-3
group by zero.id, zero.date;
/* on lst
id date sum3
------------------------------
1 2011-01-01 .
1 2011-01-02 0
1 2011-01-03 0
1 2011-01-04 1
2 2011-01-01 .
2 2011-01-02 1
2 2011-01-03 3
2 2011-01-04 6
*/
/* if there are two or more days with value=0
between (date-1) and (date-5) */
select zero.id, zero.date, sum(one.value=0)>=2 as zero2
from zero left join zero as one on zero.id = one.id and
one.date between zero.date-1 and zero.date-5
group by zero.id, zero.date;
/* on lst
id date zero2
------------------------------
1 2011-01-01 0
1 2011-01-02 0
1 2011-01-03 1
1 2011-01-04 1
2 2011-01-01 0
2 2011-01-02 0
2 2011-01-03 0
2 2011-01-04 0
*/
quit;
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!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.