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_all | Patient_ID | Pending | specimen pending max |
3/29/22 | AB1 | NO | 4/5/22 |
3/29/22 | AB1 | NO | 4/5/22 |
3/29/22 | AB1 | YES | 4/5/22 |
3/29/22 | AB1 | NO | 4/5/22 |
4/5/22 | AB1 | NO | 4/5/22 |
4/5/22 | AB1 | YES | 4/5/22 |
4/5/22 | AB1 | YES | 4/5/22 |
4/5/22 | AB1 | NO | 4/5/22 |
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;
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.