- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is a question from a practice exam I just took and I am not understanding how this iterative do loop works. Can anyone please explain why the increment of i goes past the specified range and why there is a iterative do loop within the original do loop? Thank you!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Iterated do loops ALWAYS go until the condition is no longer true. Since there is no increment included I increments by one until the value is greater than the limit.
Hint: With short examples like this type the code into your SAS editor and run it.
Maybe place some put statements in various places to see what changes where/when.
Consider this short program. Copy and paste into your editor and run it then read the LOG.
data example; do i= 0 to 5; put "in loop " i=; end; put 'after loop ' i=; run;
You can look in the log to see what happens at each iteration and examine the data set to see what the value is when the data set is created.
Then look at this one:
data example2; do i= 0 to 15 by 5; put "in loop " i=; end; put 'after loop ' i=; run;
"why there is a iterative do loop within the original do loop?" Better to say OUTER than original. Looks like someone is simulating a 10% increase in a value every calendar quarter within each year. Maybe a crude compound interest accumulation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Iterated do loops ALWAYS go until the condition is no longer true. Since there is no increment included I increments by one until the value is greater than the limit.
Hint: With short examples like this type the code into your SAS editor and run it.
Maybe place some put statements in various places to see what changes where/when.
Consider this short program. Copy and paste into your editor and run it then read the LOG.
data example; do i= 0 to 5; put "in loop " i=; end; put 'after loop ' i=; run;
You can look in the log to see what happens at each iteration and examine the data set to see what the value is when the data set is created.
Then look at this one:
data example2; do i= 0 to 15 by 5; put "in loop " i=; end; put 'after loop ' i=; run;
"why there is a iterative do loop within the original do loop?" Better to say OUTER than original. Looks like someone is simulating a 10% increase in a value every calendar quarter within each year. Maybe a crude compound interest accumulation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Excuse the lateness, but thanks so much for the response! This really helped me pass my SAS Base Certification test which had a few do loop questions. Cheers!