BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RamKumar
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Loko
Barite | Level 11

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

3 REPLIES 3
Loko
Barite | Level 11

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;

RamKumar
Fluorite | Level 6

Thanks.

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

RamKumar
Fluorite | Level 6

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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