/* 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;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.