I have multi dimensional arrays (lets say K{3,5}) that I would like to rearrange or change the order based on the minimum values of the multi dimensional arrays (L{3,5}).
Example:
data have;
input k1_1 $ k1_2 $ k1_3 $ k1_4 $ K1_5 $
k2_1 $ k2_2 $ K2_3 $ k2_4 $ k2_5 $
k3_1 $ k3_2 $ k3_3 $ k3_4 $ k3_5 $
l1_1-l1_5 l2_1-l2_5 l3_1-l3_5;
datalines;
a b c d e f g h i j k l m n o 10 5 8 7 9 8 1 2 3 4 8 8 3 20 20
run;
The minimum of L arrays are:
Hello @smend,
Try this:
/* Set array dimensions */
%let d1=3;
%let d2=5;
/* Compute minima and prepare a RENAME statement */
data minima(keep=i m);
set have;
length renlist $8000;
array t[&d2] _temporary_;
array l[&d1,&d2] l:;
do i=1 to &d1;
do j=1 to &d2;
t[j]=l[i,j];
end;
m=min(of t[*]);
renlist=catx(' ',renlist,cats('k',i,'_1-k',i,"_&d2=r",i,'_1-r',i,"_&d2 l",
i,'_1-l',i,"_&d2=s",i,'_1-s',i,"_&d2"));
output;
end;
call symputx('renlist',renlist);
run;
proc sort data=minima;
by m;
run;
/* Create new dataset with rearranged array values */
data want(keep=r: s:);
set have;
set have(rename=(&renlist));
array k[&d1,&d2] k:;
array l[&d1,&d2] l:;
array r[&d1,&d2] r:;
array s[&d1,&d2] s:;
do a=1 to &d1;
set minima;
do j=1 to &d2;
r[a,j]=k[i,j];
s[a,j]=l[i,j];
end;
end;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.