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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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