wannabe2007
Technical User
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.
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.