BookmarkSubscribeRSS Feed
lmyers2
Obsidian | Level 7

Hello

 

I'm trying to keep a row that has a date closest to but after a test result date, Below is sample data. Is it possible to do this while the data is in long form?

 

Have:

Patient      ComorbidityScore  Test Result

Patient 1   Date 1                      Date X

                 Date 2                       Date X

                  Date 3                      Date X

Patient 2    Date 1                     Date Y

                  Date 2                     Date Y

Want:

Patient      ComorbidityScore   Test Result

Patient 1   Date 3                      Date X                                   

Patient 2    Date 1                      Date Y

2 REPLIES 2
Shmuel
Garnet | Level 18

You are looking for:

  where ComorbidityScore > test_result and min(ComorbidityScore - test_result) 

  group by patient

to be used within sql.

Kurt_Bremser
Super User

Sort by patient and the date, then do

data want;
set have;
by patient;
retain flag;
if first.patient then flag = 1;
if flag and comorbidityscore > testresult
then do;
  output;
  flag = 0;
end;
drop flag;
run;

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!

5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 364 views
  • 0 likes
  • 3 in conversation