## How to find the least three values?

Solved
Regular Contributor
Posts: 168

# How to find the least three values?

I need to find out least 3 values from the list of ten variables.

e.g.

 Distance1 Distance2 Distance3 Distance4 Distance5 Distance6 Distance7 Distance8 Distance9 Distance10 15.46791785 27.07151463 28.99654603 229.332241 237.8000057 12.01979627 31.54472452 22.26341721 27.26892156 23.14074428 19.56490681 31.14826968 5.781924029 215.2916435 222.8782588 25.21045093 8.626908624 16.60635164 9.818619941 17.35681137

Desired output:

 Distance1 Distance2 Distance3 Distance4 Distance5 Distance6 Distance7 Distance8 Distance9 Distance10 min-distance1 min-distance2 min-distance3 15.46791785 27.07151463 28.99654603 229.332241 237.8000057 12.01979627 31.54472452 22.26341721 27.26892156 23.14074428 12.01979627 15.46791785 22.26341721 19.56490681 31.14826968 5.781924029 215.2916435 222.8782588 25.21045093 8.626908624 16.60635164 9.818619941 17.35681137 5.781924029 8.626908624 9.818619941

With the 'min' function we can find out only the least 1 variable, but I was why wondering to get the least three values.

Accepted Solutions
Solution
‎11-05-2014 07:47 AM
Super Contributor
Posts: 319

## Re: How to find the least three values?

Hello,

data have;
input a b c d e;
datalines;
1 2 3 4 5
10 50 20 30 40
50 60 40 30 30
;

data want;

array mindistance{3};
set have;
do i=1 to 3;
mindistance{i}=smallest(i,a,b,c,d,e);
end;

run;

All Replies
Solution
‎11-05-2014 07:47 AM
Super Contributor
Posts: 319

## Re: How to find the least three values?

Hello,

data have;
input a b c d e;
datalines;
1 2 3 4 5
10 50 20 30 40
50 60 40 30 30
;

data want;

array mindistance{3};
set have;
do i=1 to 3;
mindistance{i}=smallest(i,a,b,c,d,e);
end;

run;

Regular Contributor
Posts: 168

## Re: How to find the least three values?

Thanks.

how to find the maximum 3 values for the same scenario?

Regular Contributor
Posts: 168

## Re: How to find the least three values?

I got it. It can be done via largest function.

🔒 This topic is solved and locked.