03-07-2017 08:43 PM
I read this post here which deals with a similar issue but I unfortunately don't understand how to apply it to my situation: https://communities.sas.com/t5/Base-SAS-Programming/Comparing-a-row-in-a-dataset-with-the-next-row/t...
What I am trying to do is for each patient when the col1 goes from a 1 to a 0, then drop all following observations for that patient.
What I am trying to do is create a start and end date for each studyid based on the 1st time any of the anemia variables are 1 and the first 0 to follow. Then I'm going to attach the respective matching rdate to the anemia#s to create the start and end date. So for example I need 00RAJJ1P to take the dates from anemia2/rdate2 to anemia4/rdate4 and make those the start and enddate for that patient. For patient 00TS73B0 I would need a startdate and the enddate would be missing. for 00UQGCK2 start date and end date would be the two variables that are there.
03-07-2017 09:18 PM
Your description wasn't clear enough to insure that anyone can provide a suggested solution. However, if you're only trying to do what your first sentence descibes, then the following may be what you're looking for:
data have; input patient $ type1 $ type2 $ col1; cards; 00RAJJ1P anemia1 anemia1 0 00RAJJ1P anemia2 anemia2 1 00RAJJ1P anemia3 anemia3 1 00RAJJ1P anemia4 anemia4 0 00RAJJ1P anemia5 anemia5 1 00RAJJ1P rdate1 rdate1 19025 00RAJJ1P rdate2 rdate2 19289 00RAJJ1P rdate3 rdate3 19424 00RAJJ1P rdate4 rdate4 19493 00RAJJ1P rdate5 rdate5 19877 00RAJJ1Q anemia1 anemia1 0 00RAJJ1Q anemia2 anemia2 1 00RAJJ1Q anemia3 anemia3 1 00RAJJ1Q anemia4 anemia4 0 00RAJJ1Q anemia5 anemia5 1 00RAJJ1Q rdate1 rdate1 19025 00RAJJ1Q rdate2 rdate2 19289 00RAJJ1Q rdate3 rdate3 19424 00RAJJ1Q rdate4 rdate4 19493 00RAJJ1Q rdate5 rdate5 19877 ; data want (drop=_:); set have; retain _drops; by patient; if first.patient then _drops=0; if _drops ne 2 then output; if col1 eq 1 and _drops ne 2 then _drops=1; else if _drops eq 1 and col1 eq 0 then _drops=2; run;
Art, CEO, AnalystFinder.com