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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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