DATA Step, Macro, Functions and more

How to find the least three values?

Accepted Solution Solved
Reply
Regular Contributor
Posts: 168
Accepted Solution

How to find the least three values?

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

e.g.

Distance1Distance2Distance3Distance4Distance5Distance6Distance7Distance8Distance9Distance10
15.4679178527.0715146328.99654603229.332241237.800005712.0197962731.5447245222.2634172127.2689215623.14074428
19.5649068131.148269685.781924029215.2916435222.878258825.210450938.62690862416.606351649.81861994117.35681137

Desired output:

Distance1Distance2Distance3Distance4Distance5Distance6Distance7Distance8Distance9Distance10min-distance1min-distance2min-distance3
15.4679178527.0715146328.99654603229.332241237.800005712.0197962731.5447245222.2634172127.2689215623.1407442812.0197962715.4679178522.26341721
19.5649068131.148269685.781924029215.2916435222.878258825.210450938.62690862416.606351649.81861994117.356811375.7819240298.6269086249.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.

Appreciate your inputs in advance.


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

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;

View solution in original post


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

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.

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

Discussion stats
  • 3 replies
  • 209 views
  • 1 like
  • 2 in conversation