Copy data from first observation of group to last observation of group

Reply
Contributor
Posts: 27

Copy data from first observation of group to last observation of group

Hi All,

 

I have a dataset which is given as below.

 

A.jpg


And I want to create another dataset where I want to populate the value of Dose Freq for each patient at his last visit (mentioned as below, Please see the column X).

 

B.jpg

Can anyone tell me how to do it withing changing the sequence of the Visit and their date.

 

Many Thanks in Advance.

 

Kind Regards,

Vikrant Sawatkar

Super User
Posts: 5,085

Re: Copy data from first observation of group to last observation of group

Here's one approach that should work:

 

data want;

set have;

by patient visit;

if first.patient then foo=dose_freq;

retain foo;

if last.patient then x=foo;

drop foo;

run;

 

There are missing pieces, such as what variable names do you actually use?  Is DOSE_FREQ actually populated only on the first observation for a patient? 

 

Good luck.

Contributor
Posts: 27

Re: Copy data from first observation of group to last observation of group

##- Please type your reply above this line. Simple formatting, no
attachments. -##thanks for help. I will let you know when I try it out today
Super User
Posts: 5,257

Re: Copy data from first observation of group to last observation of group

it seems that you are mixing "real" data, with some calculations, perhaps for a report?

Not a best practice. It would be better if you have your business rule and the result of that in a separate table, with just patient id and dose_freq_last_visit.

Data never sleeps
Ask a Question
Discussion stats
  • 3 replies
  • 266 views
  • 0 likes
  • 3 in conversation