BookmarkSubscribeRSS Feed
fp
Calcite | Level 5 fp
Calcite | Level 5
Hi SAS users,

Is there any SAS function identifying the closest value to 50 in the variable B
in the a dataset below. If not, any other way to get the value without using SAS function.

Thank you
FP

data new;
input A B;
datalines;
1 50.10
1 50.2
2 49.99
2 49.7
3 49.8
3 49.90
4 50.7
4 50.3
5 50.5
5 50.6
;
run;
2 REPLIES 2
data_null__
Jade | Level 19
If you use ABS(B-50) as a distance then find MIN would that be adequate?

[pre]
data new;
input A B;
dif = abs(b-50);
datalines;
1 50.10
1 50.2
2 49.99
2 49.7
3 49.8
3 49.90
4 50.7
4 50.3
5 50.5
5 50.6
;
run;
proc summary nway;
class a;
output out=work.closest(drop=_:) idgroup(min(dif) out(b)=);
run;
proc print;
run;
[/pre]
ballardw
Super User
Does this do what you want?

proc sql;
select *
from new
where abs(50-b) =(select min(abs(50-b)) from new);
quit;

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 681 views
  • 0 likes
  • 3 in conversation