Question

Locked

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

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Share your knowledge
Back to Software Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums