BookmarkSubscribeRSS Feed
deezy55
Calcite | Level 5

Hey guys!

I need help with a specific part of my sas code.

I am supposed to use first. / last. and RETAIN to keep one record per patient and identify the highest and lowest temperature per patient.

I am working with VS(vital signs data set ) which has multiple visits per patient and multiple temperatures recorded as well as multiple blood pressure taken ect..

I have the following code, which keeps only one record per patient, but then there isnt a value for temperature for that patient, because the first time it sees usubjid (the unique subject identifier) the temperature isnt recorded then is that makes sense? I therefore am not sure how i would go about this?

** i created vitals earlier in my code

proc sort data = vitals;

by usubjid;

run;

data vitals2(keep= ftemp usubjid visitnum vstptnum);

set vitals;

by usubjid;

retain ftemp;

if first.usubjid and then output;

run;

1 REPLY 1
Peter_C
Rhodochrosite | Level 12

since one row (perpatient) cannot provide both the highest and the lowest without adapting the data to provide at least one extra column.

These challenges are often solved with an efficient approach called a DOW loop.

Should be able to find a few examples by searching the communities.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 687 views
  • 0 likes
  • 2 in conversation