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!
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
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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.