How to use .first variable in SAS data step

By h_macmullin ·
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;

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';

proc sort data= FirstVisit;
by VisitType UserID;

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

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

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Share your knowledge

Related Discussions

Related Forums