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
Super User

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 2024

Innovate_SAS_Blue.png

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. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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