data WORK.LOOP; X = 0; do Index = 1 to 5 by 2; X = Index; end; run;
Upon completion of execution, what are the values of the variables X and Index in the SAS data set named WORK.LOOP?
I knew the answer was X=5 and index=7;
Question is : When the index =5, isn't the program stop executing DO loop and gives the answer of index=5 and x=5.However, the answer was X=5 and index=.How??????
A do loop works like that:
1 - set the iteration variable to the start value
2 - compare to the end value
3 - if less or equal to the end value (greater or equal if the by value is negative), enter the body of the do, otherwise goto 6
4 - at the end of the body, increment by the by value
5 - goto 2
6 - end
So you see that the iteration variable needs to exceed the end value to terminate the iterative do loop.
A do loop works like that:
1 - set the iteration variable to the start value
2 - compare to the end value
3 - if less or equal to the end value (greater or equal if the by value is negative), enter the body of the do, otherwise goto 6
4 - at the end of the body, increment by the by value
5 - goto 2
6 - end
So you see that the iteration variable needs to exceed the end value to terminate the iterative do loop.
Thanks mr.KurtBremser.I am still in the learning curve.
Thanks for explaining.
For added education use BY 3; and predict the values.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.