I need to find patients with two or more consecutive RESULT values greater than a threshold, for example, 1000. These patients would be considered to failed treatment. I created a variable indicating results >=1000 so that the data looks like:
I sorted by PID and TEST_DATE and created a new data set by PID, but I am stuck on what to do next. Here patient 1 is a failure. I need to (1) create a variable identifying patients that experienced treatment failure; and (2) create another variable with the first date defining failure for each patient that failed. Here, for patient 1 the date of failure would be 04DEC2005.
A programming sequence involving multiple DATA steps as an approach (on sorted observations) should work. You will need to consider using MERGE to "flag" PID instances that are candidates. Also, look at using a RETAIN stmt to capture and track your "first date" conditions, as well.
Attack the requirements/tasks one at a time, as you develop your SAS application program, considering that along the way you may have some adjustments that need to be made. Use DATA step diagnostic techniques, such as one or more:
PUTLOG '>diag-nn' / _ALL_;
placed in your program, with "nn" being unique for each instance -- this helps you learn / understand the SAS observation/variable values and condition as the program executes.
Lastly, you will find a wealth of information at the SAS support http://support.sas.com/ website, including SAS-hosted product documentation and also supplemental technical/conference papers on related topics.