Hello @marleeakerson,
@marleeakerson wrote:
I am trying to run a frequency to see the frequency of people (IDs) who went from positive to negative, how many went from negative to positive, and all the other combinations (pos to neg and then back to pos, etc.).
Do you want to count an ID with, e.g., Pos followed by Neg in the same category as an ID with four times Pos followed by three times Neg (because both went from Pos to Neg), but not in the same category as an ID that after this change switched back to Pos?
If so, try this:
data want;
length seq $100;
do until(last.id);
set have;
by id result notsorted;
if first.result then seq=catx(',', seq, result);
end;
drop result;
run;
proc freq data=want;
tables seq;
run;
This assumes that your dataset (HAVE) is sorted by ID. (Add a PROC SORT step if this is not the case.) Adapt the length of character variable SEQ (100) as needed to accommodate the relevant sequences "Pos,Neg,Pos,..." etc.