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: 17,864

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

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,363

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

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: 17,864

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

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

Super User
Super User
Posts: 7,407

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

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: 17,864

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

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

do i = 1 to dim(array_name);

☑ This topic is SOLVED.

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

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