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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

Something like this:

data want;
 set have;
 by id date;
 if last.id then lastcontact=date; 
 else            lastcontact=.   ;
 format lastcontact DDMMYY10.;
run;

Koen

View solution in original post

8 REPLIES 8
Anita_n
Pyrite | Level 9

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?

Anita_n
Pyrite | Level 9

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?

sbxkoenk
SAS Super FREQ

Something like this:

data want;
 set have;
 by id date;
 if last.id then lastcontact=date; 
 else            lastcontact=.   ;
 format lastcontact DDMMYY10.;
run;

Koen

Anita_n
Pyrite | Level 9

Thanks, it worked

Anita_n
Pyrite | Level 9

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?

mkeintz
PROC Star

@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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Anita_n
Pyrite | Level 9

sorry for post so often, the data is attached in the first post

Kurt_Bremser
Super User

@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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2573 views
  • 0 likes
  • 4 in conversation