Date: Wed, 18 Apr 2012 15:08:28 +0000
Reply-To: "Keintz, H. Mark" <mkeintz@WHARTON.UPENN.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Keintz, H. Mark" <mkeintz@WHARTON.UPENN.EDU>
Subject: Re: tracking in SAS - response to previous post
In-Reply-To: <201204181315.q3I4iX0p005017@willow.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"
Rhian:
Previously I was under the impression that you wanted all sequences of 3 or more records in which:
1. All of the 3 desired categories occurred, and
2. No other category occurred.
Now it appears that you actually want all sequences of 3 or more records in which only desired categories occurred, but not necessarily all desired categories.
In that case, the task is far easier than the one I addressed in the code I sent to the list and you. You only have to track when the most recent non-qualifying record occurred. If it precedes the current record by 3 or more then you are in an eligible sequence, and should indicate same in the _R array:
data want (drop=_:);
array _r {1000}; /* Assume <=1,000 record per patient */
** Before starting each patient, indicate the most recent
record number for a non-qualifying class **;
_other_mr = 0;
do _NR=1 by 1 until (last.patientnumber);
set have;
by patientnumber;
if class (not in ('red','white','blue')) then _other_mr=_NR;
if _other_mr <= (_NR - 3) then do = _I_ = _other_mr + 1 to _nr;
_r{_I_}=1;
end;
end;
** re-read and output those flagged in the array **;
do _I_=1 to _nr;
set have;
if _R{_I_}=1 then output;
end;
run;
regards,
Mark
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of anon
Sent: Wednesday, April 18, 2012 9:15 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: tracking in SAS - response to previous post
I recently posted to the list with a query regarding tracking.
I am very grateful for the response I had, however the code that I was given does not appear to work.
Could anyone suggest anything else that I can try as I know that what I need to do is beyond my capabilities.
What I am trying to do is flag and output patients who have been classified (variable name = class) as either red white or blue for 3 OR MORE of their CONSECUTIVE visits (variable = visit)in the trial.
for example -
patientnumber visit class
101 1 yellow
101 2 red
101 3 red
101 4 white
101 5 green
Here I have patient 101 - and in 3 consecutive visits - 2,3 and 4 he has been classified as red red and white. For this reason I want this patient to be flagged and put into another new dataset.
The classification in these three or more consecutive visits can be in ANY ORDER AND ANY COMBINATION ie blue blue blue, red blue white or red red white (as above!) or blue blue blue red for example AND can occur during any period the patient is in the trial - for example it does not need to occur on the patients first visit or end at their last (above - occured at visit
2,3 and 4).
can any one help!
I have attached the previous code sent - Any help or advice would be appreciated!
data want (drop=_:);
array _r {1000}; /* Assume <=1,000 record per patient */
** Before starting each patient, initialize "most
recent" record for each value of interest and
most recent occurrence of any other value **;
_mr_red = 0;
_mr_white = 0;
_mr_blue = 0;
_other_mr = 0;
do _NR=1 by 1 until (last.patientnumber);
set have;
by patientnumber;
select (class);
when ('red') _mr_red=_NR;
when ('white') _mr_white=_NR;
when ('blue') _mr_blue=_NR;
otherwise _other_mr=_NR;
end;
/* If at least 3 records since an invalid value and every valid value has
been encountered subsequently then set corresponding array elements */
if _other_mr < _NR-2 and _other_mr < min(of _mr_:) then
do _I_ = _other_mr+1 to _nr;
_r{_I_}=1;
end;
end;
** re-read and output those flagged in the array **; do _I_=1 to _NR;
set have;
if _R{_I_}=1 then output;
end;
run;