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