Hi all,
I have a table with date values of two patients, see table data
I wish to out the last contact date of each patient, so that my table looks afterwards like this (see table test)
any help?
Something like this:
data want;
set have;
by id date;
if last.id then lastcontact=date;
else lastcontact=. ;
format lastcontact DDMMYY10.;
run;
Koen
Hi all,
I have a table with date values of two patients
id | date | lastcontact |
7 | 04.11.81 | |
7 | 26.10.88 | |
7 | 18.08.89 | |
7 | 10.12.90 | |
50 | 10.10.90 | |
50 | 16.10.98 | |
50 | 15.02.00 | |
50 | 08.05.10 | |
50 | 12.05.20 | |
50 | 22.12.20 | |
50 | 18.10.21 |
I wish to out the last contact date of each patient, so that my table looks afterwards like this
id | date | lastcontact |
7 | 04.11.81 | |
7 | 26.10.88 | |
7 | 18.08.89 | |
7 | 10.12.90 | 10.12.1990 |
50 | 10.10.90 | |
50 | 16.10.98 | |
50 | 15.02.00 | |
50 | 08.05.10 | |
50 | 12.05.20 | |
50 | 22.12.20 | |
50 | 18.10.21 | 18.10.2021 |
any help?
Hi all,
I have the following dates of different patients, I wish to output the last contact date in a different variable called last contact:
id | date |
7 | 04.11.81 |
7 | 26.10.88 |
7 | 18.08.89 |
7 | 10.12.90 |
50 | 10.10.90 |
50 | 16.10.98 |
50 | 15.02.00 |
50 | 08.05.10 |
50 | 12.05.20 |
50 | 22.12.20 |
50 | 18.10.21 |
so that the results will look like this:
id | date | lastcontact |
7 | 04.11.81 | |
7 | 26.10.88 | |
7 | 18.08.89 | |
7 | 10.12.90 | 10.12.1990 |
50 | 10.10.90 | |
50 | 16.10.98 | |
50 | 15.02.00 | |
50 | 08.05.10 | |
50 | 12.05.20 | |
50 | 22.12.20 | |
50 | 18.10.21 | 18.10.2021 |
any help?
Something like this:
data want;
set have;
by id date;
if last.id then lastcontact=date;
else lastcontact=. ;
format lastcontact DDMMYY10.;
run;
Koen
Thanks, it worked
Hi all,
I have a table with date values of two patients, see table data
I wish to out the last contact date of each patient, so that my table looks afterwards like this (see table test)
any help?
@Anita_n wrote:
Hi all,
I have a table with date values of two patients, see table data
I wish to out the last contact date of each patient, so that my table looks afterwards like this (see table test)
any help?
"see table data". Could you please post the data in the form of a working data step? Then we can provide real help.
Edit note: I see that this duplicate posting (related to problem behavior this AM?), actually had a data set. The topics are now merged.
sorry for post so often, the data is attached in the first post
@Anita_n wrote:
sorry for post so often, the data is attached in the first post
In unusual fashion (Excel files). Please provide data steps with datalines, they leave no doubt about variable attributes and contents.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.