Hi all, New to loops in SAS and need some help with syntax and logic. My input table looks like the following: GROUP DATE ACTIVATED 1 1/11/20 1 1 2/11/20 0 1 3/11/20 1 2 1/11/20 0 2 2/11/20 0 3 1/11/20 1 3 2/11/20 1 3 3/11/20 0 and I need to add a flag to identify any inactivation (ACTIVATED=0) if there is at least one activation(ACTIVATED=1) within 35 days. So here is the table result I would like to have: GROUP DATE ACTIVATED FLAG 1 1/11/20 1 0 1 2/11/20 0 1 1 3/11/20 1 0 2 1/11/20 0 0 2 2/11/20 0 0 3 1/11/20 1 0 3 2/11/20 1 0 3 3/11/20 0 1 Here is the code I tried that I think the logic was okay, but I'm not familiar with the syntax in SAS. The idea is to have two pointers to go through all pairs in each group. data want;
set input;
by GROUP;
retain FLAG 0;
do i = first.GROUP to last.GROUP;
do j = i+1 to last.GROUP;
if -35 <= intck('DAY', i.DATE, j.DATE) <= 35 and i.ACTIVATED = 0 and j.ACTIVATED = 1 then i.FLAG=1;
else if -35 <= intck('DAY', i.DATE, j.DATE) <= 35 and i.ACTIVATED = 1 and j.ACTIVATED = 0 then j.FLAG=1;
end;
end;
run; Any inputs would be appreciated!
... View more