DATA Step, Macro, Functions and more

Finding Two Consecutive Equal Values within Subjects - Long Data Format

Reply
N/A
Posts: 0

Finding Two Consecutive Equal Values within Subjects - Long Data Format

Hi All,

I have longitudinal clinical data in the long format, where patients get multiple labs over the course of treatment. For example:

PID TEST_DATE RESULT
1 02JUN2005 399
1 11SEP2005 412
1 04DEC2005 1002
1 02FEB2006 2700
2 18FEB2007 53
2 09MAR2007 102

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:

PID TEST_DATE RESULT X1000
1 02JUN2005 399 0
1 11SEP2005 412 0
1 04DEC2005 1002 1
1 02FEB2006 2700 1
2 18FEB2007 53 0
2 09MAR2007 102 0

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.

Any suggestions?

Thanks!
Super Contributor
Super Contributor
Posts: 3,174

Re: Finding Two Consecutive Equal Values within Subjects - Long Data Format

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.

Scott Barry
SBBWorks, Inc.
Super Contributor
Posts: 474

Re: Finding Two Consecutive Equal Values within Subjects - Long Data Format

Hello.

This would be easily done, by retaining the previous observation (and comparing with the current one) of the sorted dataset.

Check the online documention of the RETAIN statement here:
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000214163.htm

See also some more reading about retaining values:
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001310768.htm

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.
Ask a Question
Discussion stats
  • 2 replies
  • 117 views
  • 0 likes
  • 3 in conversation