BookmarkSubscribeRSS Feed
branbran
Calcite | Level 5

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?

2 REPLIES 2
Haikuo
Onyx | Level 15

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)

;

quit;

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

Haikuo

Ksharp
Super User

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

proc sort data=have;

by pid descending age descending visit;

run;

proc sort data=have out=want nodupkey;

by pid ;

run;

Ksharp

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 421 views
  • 0 likes
  • 3 in conversation