DATA Step, Macro, Functions and more

Finding observations with value closest to a fixed value

Reply
New User
Posts: 1

Finding observations with value closest to a fixed value

Hi all

I want to keep an observation with a variable closet to a fixed value.

Example:

Data contain;
Input age rank;
85 0
84 1
86 2
83 3
87 4
88 5
89 6
90 7
91 8
92 9
93 10
94 11
95 12
96 13
97 14
98 15
99 16;

So, I want to keep the the age close to 100.
Super User
Posts: 6,939

Re: Finding observations with value closest to a fixed value

Quick SQL:

proc sql;
select *, abs(100 - age) as dist
from contain
having dist = min(dist)
;
quit;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 1 reply
  • 53 views
  • 1 like
  • 2 in conversation