Hi Commuinity,
I have a Vital Signs dataset below which I want to add a column to flag the differences of Systolic Blood Pressure from Baseline to 2 hours, 2 hours to 24 hours. 24 hours to 48 hours and 48 hours to Day 5 for every single patient in the dataset.
Any ideas?
Thank you
Patient | Visit | Systolic Blood Pressure | Diastolic Blood Pressure |
1001 | Baseline | 146 | 82 |
1001 | hr2 | 119 | 59 |
1001 | hr24 | 133 | 71 |
1001 | hr48 | 102 | 51 |
1001 | D5 | 128 | 77 |
1002 | Baseline | 122 | 76 |
1002 | hr2 | 150 | 78 |
1002 | hr24 | 115 | 61 |
1002 | hr48 | 121 | 73 |
1002 | D5 | 142 | 85 |
1003 | Baseline | 102 | 59 |
1003 | hr2 | 110 | 77 |
1003 | hr24 | 111 | 58 |
1003 | hr48 | 124 | 78 |
1003 | D5 | 108 | 68 |
You want a sequence of differences between systolicbp{I}-systolicbp{i-1}, where i is the observations number. And for the first obs of each patient, you want the difference reset to missing.
Use the DIF function, which is defined as DIF(x)=x-lag(X).
data want;
set have;
by patient;
systolic_diff=dif(systolicbp);
if first.patient then systolic_diff=.;
run;
Edited addition: I should have added that this program assumes there are no "holes" in the data. I.e. each patient has a record for every time point, in sequence.
proc transform would be the tool I would use.
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/
then evaluate the your client across your time progression of base, 2, 24, 48 and day5 by arraying the time intervals
You want a sequence of differences between systolicbp{I}-systolicbp{i-1}, where i is the observations number. And for the first obs of each patient, you want the difference reset to missing.
Use the DIF function, which is defined as DIF(x)=x-lag(X).
data want;
set have;
by patient;
systolic_diff=dif(systolicbp);
if first.patient then systolic_diff=.;
run;
Edited addition: I should have added that this program assumes there are no "holes" in the data. I.e. each patient has a record for every time point, in sequence.
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!
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.
Ready to level-up your skills? Choose your own adventure.