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?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.