DATA Step, Macro, Functions and more

Getting a day as close to zero as possible

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Getting a day as close to zero as possible

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:

IDHeightHt_daysPulm_testdayDiff_days
117063135627-686
117163695627-742
117262485627-621
117347075627920
117447565627871
117548305627797
117648935627734
215034133060-353
2150.234203060-360
2150.334373060-377
215235423060-482
31696259634283
31706306634236
3170.3634263420
317263486342-6
317264046342-62

 


Accepted Solutions
Solution
‎04-04-2018 11:52 AM
Super User
Posts: 24,004

Re: Getting a day as close to zero as possible

[ Edited ]

Do you care if its before or after?

 

  1. If not, make the diff_days an absolute value instead of negative and positive.
  2. Sort by ID and diff_days
  3. Keep or flag the first record which will be the minimum. 

@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

 


 

 

 

View solution in original post


All Replies
Solution
‎04-04-2018 11:52 AM
Super User
Posts: 24,004

Re: Getting a day as close to zero as possible

[ Edited ]

Do you care if its before or after?

 

  1. If not, make the diff_days an absolute value instead of negative and positive.
  2. Sort by ID and diff_days
  3. Keep or flag the first record which will be the minimum. 

@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

 


 

 

 

Occasional Contributor
Posts: 12

Re: Getting a day as close to zero as possible

Thanks, Reeza! You always come through for me!
Super User
Posts: 2,061

Re: Getting a day as close to zero as possible

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

Occasional Contributor
Posts: 12

Re: Getting a day as close to zero as possible

Posted in reply to novinosrin
Thanks, novinosrin! That works too.

I used the following code:

proc means data=one max min maxdec=1;
class study_id;
var diff_day;
output out=min_ht;
run;

data min_ht1;
set min_ht;
where _STAT_ = 'MIN';
drop _TYPE_ _FREQ_ _STAT_;
run;
Occasional Contributor
Posts: 12

Re: Getting a day as close to zero as possible

I took the absolute value of the difference and then ran proc means.
Super User
Posts: 13,941

Re: Getting a day as close to zero as possible


@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

Occasional Contributor
Posts: 12

Re: Getting a day as close to zero as possible

All dates are PHI, unfortunately. I missed to mention that in my question.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 150 views
  • 3 likes
  • 4 in conversation