Nested Do Loops

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

Nested Do Loops

I'm trying to create a series of iterations in where I'm looping through 2 variables separately...

my starting data set would have apr = .22 and months = 36. What i want to do is create a do loop that would iterate the months down to 24 by 3 ( from 36 to 24 in this case ) while keeping the apr the same. Then, subtract 1% from the apr, then use that new value to loop through the months again... so the final data set would look something like this:

Iteration     apr      months

1                0.22         36

2                0.22         33

3                0.22         30

4                0.22         27

5                0.22         24

6                0.21         36

7                0.21         33

8                0.21         30

9                0.21         27

10              0.21         24

I've tried a few nested loops but can't seem to get it right, any ideas? All responses are greatly appreciated!

Here is a quick datastep to create the original data:

data x;

apr=.22;

months=36;

run;


Accepted Solutions
Solution
‎12-02-2013 12:51 PM
Super User
Super User
Posts: 7,050

Re: Nested Do Loops

do apr=.22 to .21 by -.01 ;

  do months=36 to 24 by -3 ;

     output;

  end;

end;

View solution in original post


All Replies
Solution
‎12-02-2013 12:51 PM
Super User
Super User
Posts: 7,050

Re: Nested Do Loops

do apr=.22 to .21 by -.01 ;

  do months=36 to 24 by -3 ;

     output;

  end;

end;

Contributor
Posts: 50

Re: Nested Do Loops

I knew I was over-thinking it, Thank You!

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 156 views
  • 0 likes
  • 2 in conversation