BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Rhodochrosite | Level 12

Hello Experts,

 

I'm applying the following code :

proc standard data=bdd_1 mean=0 std=1 out=bdd_2 _std_data;
run;

proc distance data= bdd_2 _std_data method=euclid out=distances;
	var interval (&var_all.);
	id LIB;
run;

How do I retrieve the 5 maximum distances? Thank you for your help !

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data bdd_1;
 set sashelp.heart(obs=200);
 keep _numeric_;
run;

proc standard data=bdd_1 mean=0 std=1 out=bdd_2_std_data;
run;

proc distance data= bdd_2_std_data method=euclid out=distances;
	var interval (_numeric_);
run;



data temp;
set distances;
array x{*} _numeric_;
row=_n_;
do col=1 to _n_;
 distance=x{col};output;
end;
keep row col distance;
run;
proc sort data=temp out=want;
by descending distance;
run;

proc print data=want(obs=5) noobs;
run;

View solution in original post

3 REPLIES 3
Ksharp
Super User
data bdd_1;
 set sashelp.heart(obs=200);
 keep _numeric_;
run;

proc standard data=bdd_1 mean=0 std=1 out=bdd_2_std_data;
run;

proc distance data= bdd_2_std_data method=euclid out=distances;
	var interval (_numeric_);
run;



data temp;
set distances;
array x{*} _numeric_;
row=_n_;
do col=1 to _n_;
 distance=x{col};output;
end;
keep row col distance;
run;
proc sort data=temp out=want;
by descending distance;
run;

proc print data=want(obs=5) noobs;
run;
SASdevAnneMarie
Rhodochrosite | Level 12

Thank you, Ksharp!

FreelanceReinh
Jade | Level 19

Hello @SASdevAnneMarie,

I'm sure you marked your own "thank you" post as the solution only by mistake. You can correct this easily: Select Ksharp's post as the solution after clicking "Not the Solution" in the option menu (see icon below) of the current solution.
show_option_menu.png

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore 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
  • 362 views
  • 2 likes
  • 3 in conversation