Hello!
I have a data set that measures the height of patients at different time points and their pulmonary function at one particular time point. I was not given the dates of the measurements as they are PHI. My task is to obtain the height that is measured as close to the pulmonary function test day as possible. I am not sure how to do this without complicating. Can you please help me? Thanks in advance.
Height - Height in cm
Ht_days = Date of diagnosis - clinical visit date
Pulm_testday = Date of diagnosis - Pulmonary function test date
Diff_days = Ht_days - Pulm_testday
Here's an excerpt of the data set:
ID | Height | Ht_days | Pulm_testday | Diff_days |
1 | 170 | 6313 | 5627 | -686 |
1 | 171 | 6369 | 5627 | -742 |
1 | 172 | 6248 | 5627 | -621 |
1 | 173 | 4707 | 5627 | 920 |
1 | 174 | 4756 | 5627 | 871 |
1 | 175 | 4830 | 5627 | 797 |
1 | 176 | 4893 | 5627 | 734 |
2 | 150 | 3413 | 3060 | -353 |
2 | 150.2 | 3420 | 3060 | -360 |
2 | 150.3 | 3437 | 3060 | -377 |
2 | 152 | 3542 | 3060 | -482 |
3 | 169 | 6259 | 6342 | 83 |
3 | 170 | 6306 | 6342 | 36 |
3 | 170.3 | 6342 | 6342 | 0 |
3 | 172 | 6348 | 6342 | -6 |
3 | 172 | 6404 | 6342 | -62 |
Do you care if its before or after?
@jomag wrote:
Hello!
I have a data set that measures the height of patients at different time points and their pulmonary function at one particular time point. I was not given the dates of the measurements as they are PHI. My task is to obtain the height that is measured as close to the pulmonary function test day as possible. I am not sure how to do this without complicating. Can you please help me? Thanks in advance.
Height - Height in cm
Ht_days = Date of diagnosis - clinical visit date
Pulm_testday = Date of diagnosis - Pulmonary function test date
Diff_days = Ht_days - Pulm_testday
Here's an excerpt of the data set:
ID Height Ht_days Pulm_testday Diff_days 1 170 6313 5627 -686 1 171 6369 5627 -742 1 172 6248 5627 -621 1 173 4707 5627 920 1 174 4756 5627 871 1 175 4830 5627 797 1 176 4893 5627 734 2 150 3413 3060 -353 2 150.2 3420 3060 -360 2 150.3 3437 3060 -377 2 152 3542 3060 -482 3 169 6259 6342 83 3 170 6306 6342 36 3 170.3 6342 6342 0 3 172 6348 6342 -6 3 172 6404 6342 -62
Do you care if its before or after?
@jomag wrote:
Hello!
I have a data set that measures the height of patients at different time points and their pulmonary function at one particular time point. I was not given the dates of the measurements as they are PHI. My task is to obtain the height that is measured as close to the pulmonary function test day as possible. I am not sure how to do this without complicating. Can you please help me? Thanks in advance.
Height - Height in cm
Ht_days = Date of diagnosis - clinical visit date
Pulm_testday = Date of diagnosis - Pulmonary function test date
Diff_days = Ht_days - Pulm_testday
Here's an excerpt of the data set:
ID Height Ht_days Pulm_testday Diff_days 1 170 6313 5627 -686 1 171 6369 5627 -742 1 172 6248 5627 -621 1 173 4707 5627 920 1 174 4756 5627 871 1 175 4830 5627 797 1 176 4893 5627 734 2 150 3413 3060 -353 2 150.2 3420 3060 -360 2 150.3 3437 3060 -377 2 152 3542 3060 -482 3 169 6259 6342 83 3 170 6306 6342 36 3 170.3 6342 6342 0 3 172 6348 6342 -6 3 172 6404 6342 -62
data have;;
input ID Height Ht_days Pulm_testday Diff_days;
datalines;
1 170 6313 5627 -686
1 171 6369 5627 -742
1 172 6248 5627 -621
1 173 4707 5627 920
1 174 4756 5627 871
1 175 4830 5627 797
1 176 4893 5627 734
2 150 3413 3060 -353
2 150.2 3420 3060 -360
2 150.3 3437 3060 -377
2 152 3542 3060 -482
3 169 6259 6342 83
3 170 6306 6342 36
3 170.3 6342 6342 0
3 172 6348 6342 -6
3 172 6404 6342 -62
;
proc sql;
create table want as
select *
from have
group by id
having abs(diff_days)=min(abs(Diff_days));
quit;
@jomag If i understand you correctly, You have done most of the work actually, mine is just a finishing touch
@jomag wrote:
Hello!
I have a data set that measures the height of patients at different time points and their pulmonary function at one particular time point. I was not given the dates of the measurements as they are PHI. My task is to obtain the height that is measured as close to the pulmonary function test day as possible. I am not sure how to do this without complicating. Can you please help me? Thanks in advance.
Height - Height in cm
Ht_days = Date of diagnosis - clinical visit date
Pulm_testday = Date of diagnosis - Pulmonary function test date
Diff_days = Ht_days - Pulm_testday
Here's an excerpt of the data set:
ID Height Ht_days Pulm_testday Diff_days 1 170 6313 5627 -686 1 171 6369 5627 -742 1 172 6248 5627 -621 1 173 4707 5627 920 1 174 4756 5627 871 1 175 4830 5627 797 1 176 4893 5627 734 2 150 3413 3060 -353 2 150.2 3420 3060 -360 2 150.3 3437 3060 -377 2 152 3542 3060 -482 3 169 6259 6342 83 3 170 6306 6342 36 3 170.3 6342 6342 0 3 172 6348 6342 -6 3 172 6404 6342 -62
Do you have the date of diagnosis. You say explicitly that the dates of measurement are PHI but not if the diagnosis was.
If so merge the diagnosis date and apply some simple algebra to get:
clinical visit date = date of diagnosis - Ht_days
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.
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.