BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
gamotte
Rhodochrosite | Level 12
As you can see, the array is declared as
array a_mngrs {*} a--c;
That is all columns from a to c. If you have more managers, just indicate the first and the last instead of a and c.
wizkid2050
Fluorite | Level 6

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.

gamotte
Rhodochrosite | Level 12
You can use _NUMERIC_ instead of a--c to select all numeric columns of the transposed dataset.
wizkid2050
Fluorite | Level 6
Awesome work man.!! Kudos. It works.
wizkid2050
Fluorite | Level 6
But i tried adding d with count 42 to check. its only giving 10 observations in output.
Just check with this condition.
gamotte
Rhodochrosite | Level 12
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;
wizkid2050
Fluorite | Level 6
Now this is exactly i was looking for. Great job.
gamotte
Rhodochrosite | Level 12

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.

Astounding
PROC Star

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?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register 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
  • 23 replies
  • 3313 views
  • 4 likes
  • 4 in conversation