BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ChuksManuel
Pyrite | Level 9

Hello programmers,

 

How can i use the lag function to print out patients that have 15% or more reduction in systolic BP and 8% or more reduction in diastolic BP between visits 1 and 5.

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
This paper is a good reference for leads/lags and how they work.
https://support.sas.com/resources/papers/proceedings16/11221-2016.pdf

View solution in original post

3 REPLIES 3
ChuksManuel
Pyrite | Level 9

DATA five;
SET four;
lag_systolic = lag(systolic);
dif_systolic = systolic - lag_systolic;
per_incr_sys = (dif_systolic/lag_systolic)*100;
RUN;
proc print; run;

data six;
set five;
lag_diastolic = lag(diastolic);
dif_diastolic= diastolic- lag_diastolic;
per_incr_dia = (dif_diastolic/lag_diastolic)*100;
run;
proc print; run;

data seven;
set six;
if per_incr_sys =< -15 and per_incr_dia =<-8 then output;
run;
proc print; run;

Reeza
Super User
My default would be to recommend RETAIN or data step merge instead.

You could use LAG4/LAG5 but then you need to be absolutely sure you'll have the correct number of records for each ID (5 visits).

You may also want to look into the DIF() function instead of LAG() same idea, except it differences automatically. Same concept though, need to be sure you have the correct number of observations.
Reeza
Super User
This paper is a good reference for leads/lags and how they work.
https://support.sas.com/resources/papers/proceedings16/11221-2016.pdf

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3 replies
  • 1029 views
  • 0 likes
  • 2 in conversation