Working with Ages

Occasional Contributor
Posts: 6

Working with Ages

Hi everyone,

For my current project I need to create one profile for each patient based on many different medical visits. I am wondering if there is a way to tell SAS to only keep the record from the most recent visit (when the patient was the oldest). Each patient reports their age for each visit and there is a unique identifier for each person. I have figured out how to drop the duplicates when the age was the same, now I need to figure out how to get only the most recent records from each patient (the record when they were the oldest). Any suggestions on how I could do this in SAS?

Respected Advisor
Posts: 3,167

Re: Working with Ages

So you don't have a visit date to associate with each visit? Using patient reported age seems shaky. But if that is only what you can leverage, Proc SQL seems to have a straightforward approach:

proc sql;

  select * from have

  group by patid

having age=max(age)



patid is the patient identifier, change it to fit your variable name.


Super User
Posts: 10,761

Re: Working with Ages

You'd better to post some dummy data to explain your question more clear.

proc sort data=have;

by pid descending age descending visit;


proc sort data=have out=want nodupkey;

by pid ;



Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation