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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1202 views
  • 0 likes
  • 2 in conversation