That's fine but what if dont want to keep changing the first and last values. may be i just want my code to work for all datasets thrown at it.
data test3;
set tr_test2;
/*keep managers;*/
array a_mngrs {*} _NUMERIC_;
if _N_=1 then index=1;
do i=1 to &n_accounts.;
if min(of a_mngrs{*}) lt 50 then do;
do j=1 to dim(a_mngrs);
if a_mngrs{index} lt 50 then do;
a_mngrs{index}=a_mngrs{index}+1;
managers=vname(a_mngrs{index});
j=dim(a_mngrs); /* Exit loop on j*/
output;
end;
/* Probably a better way to do this */
index=mod(index+1,dim(a_mngrs));
if index=0 then index=dim(a_mngrs);
end;
end;
else do;
i=&naccounts.; /* Exit loop on i */
end;
end;
run;
You're welcome. There is still a typo you probably noticed
else do;
i=&n_accounts.; /* Exit loop on i */
end;
I forgot the underscore in &n_accounts.
Also, you can uncomment the keep that i commented for debug.
Explain the stopping condition a bit more ... how does count reach 50?
If a solution involved sorting (and yet still got the answer you wanted) is that feasible or is your data set too large?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.