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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 676 views
  • 0 likes
  • 3 in conversation