BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I am trying to split a dataset into two datasets. My dataset consists of three variables, patient, note_date, note. For example, the dataset has many patients and each patient has many records. I am trying to determine what is the first visit date for each patient and then seperate the dataset into one dataset containg all patients with their first visits only and a dataset with all patients with all visits except the first one. For clarity the patient can have more than one first visit date. I tried using first. but can't seem to work out the logic. Any help is appreciated.
3 REPLIES 3
deleted_user
Not applicable
Well I figured this one out.

My code is below.

proc sort data=progressnotes;
by pat_name note_date;
run;

data temp;
set progressnotes;
format n_date mmddyy10.;
n_date=DATEPART(note_date);
run;

data temp;
set temp;
retain first_visit;
format first_visit mmddyy10.;
by pat_name note_date;
if first.pat_name then do;
first_visit=n_date;
end;
run;
Cynthia_sas
SAS Super FREQ
Hi:
In order to streamline your code, this construction:

[pre]
data temp;
set temp;
[/pre]

is not needed. Since progressnotes is sorted and you are creating n_date only for the purpose of creating first_visit for every obs in a patient group, you can do everything you need in one data step program. You might, instead, consider code like this:
[pre]
proc sort data=progressnotes;
by pat_name note_date;
run;

data temp;
retain first_visit;
format first_visit mmddyy10.
n_date mmddyy10.;

set progressnotes;
by pat_name note_date;

n_date=DATEPART(note_date);

if first.pat_name then do;
first_visit=n_date;
end;
run;
[/pre]

If you don't want a separate n_date on every obs, then you could just have
[pre]
first_visit=datepart(note_date);
[/pre]

But you must have wanted a separate n_date on every obs, since you put it there in a separate data step program. At any rate, you can create n_date and first_visit in the same program.

cynthia
deleted_user
Not applicable
Thanks Cynthia,

I don't mind shortening my code.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 3 replies
  • 1129 views
  • 0 likes
  • 2 in conversation