BookmarkSubscribeRSS Feed
rebelde52
Fluorite | Level 6

Hello, 

 

I have a small subset of patient data that that includes all their specimen dates. I also have a Pending column where some rows are associated with a "YES" for the Pending column. However I want to create a new column with a "Pending Max Date" where it takes the oldest date in their specimen date and repeats for all their rows so that I can compare the dates for an exclusion. 

 

I was thinking of using Proc SQL and using the max and group by function but I have little experience with proc sql so any help would be great!

 

Below is what i'd like my table to look like.

 

Specimendate_allPatient_IDPendingspecimen pending max
3/29/22AB1NO4/5/22
3/29/22AB1NO4/5/22
3/29/22AB1YES4/5/22
3/29/22AB1NO4/5/22
4/5/22AB1NO4/5/22
4/5/22AB1YES4/5/22
4/5/22AB1YES4/5/22
4/5/22AB1NO4/5/22
2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

The oldest date and the MAX date are two different things. 

 

I think you want to do this

 

data have;
input Specimendate_all :mmddyy10. Patient_ID $ Pending $;
format Specimendate_all mmddyy10.;
infile datalines dlm = ',' missover;
datalines;
03/29/22,AB1,NO  
03/29/22,AB1,NO  
03/29/22,AB1,YES 
03/29/22,AB1,NO  
04/05/22,AB1,NO  
04/05/22,AB1,YES 
04/05/22,AB1,YES 
04/05/22,AB1,NO  
;


proc sql;
   create table want as
   select *, max(Specimendate_all) as specimenpendingmax format = mmddyy10.
   from have
   ;
quit;
LinusH
Tourmaline | Level 20

It looks like you want the newest date, not the oldest...?

Untested:

proc sql;
   create table want as
      select *,
               max(case pending when 'YES' then specimentdata_all else 0 end) as specimen_pending_max
      from have
      group by patient_id;
quit;

 

Data never sleeps

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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