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?

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 23 replies
  • 2076 views
  • 4 likes
  • 4 in conversation