Hi @ankitasharma,
Only the DO-UNTIL approach is correct (assuming that you mean Int=0.0375). With the iterative DO loop (do Total=100 to 200;) Total is incremented by 1 at the end of each iteration (i.e. after the OUTPUT statement has executed), which is not what you want. You can replicate this behavior (just for demonstration) with the DO-UNTIL approach by inserting
total+1;
between the OUTPUT and END statements.
Related quote from the help file "DO Statement, Iterative":
CAUTION: |
Avoid changing the index variable within the DO group.
|
You are going to see a difference starting with the second time through the loop.
When you use DO UNTIL ( total ge 200) the value of total does not change from the end of one iteration of the loop to the start of the second.
But when you use DO TOTAL=100 to 200 (note that the increment amount will be 1 since it is not specified) the value of TOTAL is increased by 1 at the start of each new iteration.
Year | Total In | Total Out | Total In | Total Out | |
1 | 100 | 103.75 | 100 | 103.75 | |
2 | 103.75 | 107.6406 | 104.75 | 108.6781 | |
3 | 107.6406 | 111.6771 | 109.6781 | 113.7911 | |
4 | 111.6771 | 115.865 | 114.7911 | 119.0957 |
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.