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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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