How to write a do-loop for an array containing different number of variables?

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

How to write a do-loop for an array containing different number of variables?

I have a macro that will be initialized on different arrays, but the arrays have different number of variables, thus I was wondering how I would write the do loop to cover the length of both arrays. So the first array has 10 variables but the other array has 20 variables. My goal is do i=1 to (max). (but not sure how to write this in SAS). Thanks


Accepted Solutions
Solution
‎12-18-2014 07:01 PM
Super User
Posts: 19,878

Re: How to write a do-loop for an array containing different number of variables?

Posted in reply to Butters_Scotch

Use the dim() function to get the length of the array.

do i = 1 to dim(array_name);

View solution in original post


All Replies
PROC Star
Posts: 7,492

Re: How to write a do-loop for an array containing different number of variables?

Posted in reply to Butters_Scotch

It will be easier to respond if you post your code.

New Contributor
Posts: 4

Re: How to write a do-loop for an array containing different number of variables?

True, sorry about that. Thanks though!

Super User
Posts: 19,878

Re: How to write a do-loop for an array containing different number of variables?

Posted in reply to Butters_Scotch

Is your question answered? If so, please mark as answered.

Super User
Super User
Posts: 7,997

Re: How to write a do-loop for an array containing different number of variables?

Posted in reply to Butters_Scotch

Hi,

I agree with Arthur, post your code so we can see what your trying to do, not sure why you would want arrays and macros?

Solution
‎12-18-2014 07:01 PM
Super User
Posts: 19,878

Re: How to write a do-loop for an array containing different number of variables?

Posted in reply to Butters_Scotch

Use the dim() function to get the length of the array.

do i = 1 to dim(array_name);

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 223 views
  • 2 likes
  • 4 in conversation