Hi SASCommunity - I have a set of participants and a set of dates that are divided into active(active=1) and postactive(active=0) periods. I'd like to flag the first date of each active period for each partipant. For example, in the following dataset I would like to have a FLAG variable as follows (forgive me if syntaxical error here - I'm a NEWBY to SAS): data participantperiods; input participants dates active FLAG; datalines; 1 date1 1 1 1 date2 1 0 1 date3 0 0 2 date4 1 1 2 date5 1 0 2 date6 1 0 2 date7 0 0 2 date8 0 0; run; I would like this to be in the form of a classic 2xDoW loop. This is what I have developed so far, but it is overflagging unfortunately: data WANT;
do until (last.PARTICIPANT);
set HAVE;
by PARTICIPANT;
if first.PARTICIPANT then FIRSTFLAG=1;
end;
do until (last.PARTICIPANT);
set HAVE;
by PARTICIPANT;
output;
end;
do until (last.PARTICIPANT);
set HAVE;
by PARTICIPANT;
if FIRSTFLAG=1 and ACTIVE=1 then FIRSTACTIVEFLAG=1;
end;
do until (last.case_no);
set Encountersbydayvendor4;
by case_no;
output;
end;
run;
... View more