Question Locked

How to use .first variable in SAS data step

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Scenario: Want to pull only the first record of a dataset by user ID (may be duplicates for any given user) by earliest date and record number ID (may be duplicates for any given user). This is what I?ve tried so far and it is not always pulling the first visit.

proc sort data=FirstVisit;
by UserID DATE RecordNo;
run;

data FirstVisit;
set FirstVisit;
/*maybe I should be using a retain statement here???)
by UserID DATE RecordNo;
/*If it was their first offer*/
if first.UserID then VisitType = 'Initial Visit';
else VisitType = 'FollowupVisit';
run;

proc sort data= FirstVisit;
by VisitType UserID;
run;

data Visits;
set Visits;
keep UserID VisitType DATE RecordNo;
if VisitType = ?Initial Visit';
run;

Thanks for any suggestions re above data steps or alternative code you may be able to provide. Much appreciated.

1 reply

This discussion is closed to new replies.