BookmarkSubscribeRSS Feed
roger864
Calcite | Level 5

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...

anemiaexample.png

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. 

1 REPLY 1
art297
Opal | Level 21

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;

HTH,

Art, CEO, AnalystFinder.com

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1349 views
  • 0 likes
  • 2 in conversation