BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SannaSanna
Quartz | Level 8

Hello,

 

Looking for some assistance.  I have a large table with multiple date columns per ID.  I need to produce results that include the original table plus two new columns that will include the earliest date and the last date per ID.   I have included a couple of rows with some sample data. Each of these two IDs contain data for 3 different visits on 3 different dates.  The last two columns is what I would like the results to show- the earliest date and the very last date.   Any help would be appreciated

              WANT WANT
ID Visit1 Site1 Visit2 Site2 Visit3 Site3 Earliest Last
Inn342 3/21/2020 Loc 2/10/2019 Riv 4/1/2020 Bur 2/10/2019 4/1/2020
Rob982 1/19/2021 Sha 5/23/2020 Sie 7/2/2018 The 7/2/2018 1/19/2021
                 

.  Thank you all for reading and helping!

 

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ
data have;
informat Visit1 - Visit3 mmddyy10.;
format   Visit1 - Visit3 date9.;
input ID $	Visit1 Site1 $ Visit2 Site2	$ Visit3 Site3 $;
cards;
Inn342	3/21/2020	Loc	2/10/2019	Riv	4/1/2020	Bur
Rob982	1/19/2021	Sha	5/23/2020	Sie	7/2/2018	The
;
run;

data want; 
 set have;
 Earliest = min(of Visit1-Visit3);
 Last     = max(of Visit1-Visit3); 
 format Visit1 - Visit3 Earliest Last date9.;
run;
/* end of program */


Koen

View solution in original post

2 REPLIES 2
sbxkoenk
SAS Super FREQ
data have;
informat Visit1 - Visit3 mmddyy10.;
format   Visit1 - Visit3 date9.;
input ID $	Visit1 Site1 $ Visit2 Site2	$ Visit3 Site3 $;
cards;
Inn342	3/21/2020	Loc	2/10/2019	Riv	4/1/2020	Bur
Rob982	1/19/2021	Sha	5/23/2020	Sie	7/2/2018	The
;
run;

data want; 
 set have;
 Earliest = min(of Visit1-Visit3);
 Last     = max(of Visit1-Visit3); 
 format Visit1 - Visit3 Earliest Last date9.;
run;
/* end of program */


Koen

SannaSanna
Quartz | Level 8
omygosh- i did not think to use min/max. Thank you so much Koen!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 839 views
  • 0 likes
  • 2 in conversation