BookmarkSubscribeRSS Feed
☑ This topic is solved. 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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 421 views
  • 0 likes
  • 2 in conversation