data have2;
retain &varlist;
set have;
Array Apples_ {*} apples1-apples20;
Array Carrot_{*} Carrots1-carrots20;
Array oranges_{*} oranges1-oranges20;
Earlyfruit=min(of apples_[*]);
index_earlyfruit = whichn(earlyfruit, of apples_(*));
afruit = carrot_(index_earlyfruit);
bfruit = oranges_(index_earlyfruit);
run;
Use WHICHN to find the index of the minimum value. Note that if you have ties, the first one is returned.
@JMagenta wrote:
Awesome!
Thank you so much!
But for the last part, where I create new variables, it gets tricky.
Could this work?
data have2; retain &varlist; set have; Array Apples_ {*} apples1-apples20; Array Carrot_{*} Carrots1-carrots20; Array oranges_{*} oranges1-oranges20; do i=1 to dim(apples_); Earlyfruit=min(of apples_[*]); Afruit=Carrot_[min(of apples_[*])]; /* I want the carrot that is chosen to match the suffix of Apple without changing the value of Carrot*/ Bfruit=Oranges_[min(of apples_[*])]; /* same here with Oranges*/ end; run;
... View more