ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 34

The following SAS program is submitted:
data work.clients;
calls = 6;
do while (calls le 6);
calls + 1;
end;
run;
Which one of the following is the value of the variable CALLS in the output data set?
A. 4
B. 5
C. 6
D. 7
Click Comment link to get answer

19 comments:

  1. Hi....Why is it 7 ?? calls i not less than 6 ??

    ReplyDelete
    Replies
    1. DO WHILE (evaluates at the top of the loop) Now, calls=6 is equal to 6 therefore calls le 6 is TRUE. DO LOOP is executed. So, calls = calls +1 = 7

      Now, calls=7 is greater than 6 therefore calls le 6 is FALSE. DO LOOP is not executed.

      Hence, the value of calls remains 7

      Delete
    2. le means "less than or equal to"

      Delete
  2. Anonymous4:59 AM

    plz write the comments

    ReplyDelete
  3. the answer is D, because 'le' means "less than or equal".

    ReplyDelete
  4. Anonymous11:18 AM

    Calls=6

    So the program will execute once, and add 1 to calss to get to 7, because the condition says: While calls LE 6.

    ReplyDelete
  5. Anonymous8:22 AM

    A while condition isn't checked until the end of the loop, so the first time through, +1 is added to calls, resulting in 6- then the condition is checked and it stops.

    Answer is D

    ReplyDelete
    Replies
    1. Anonymous10:30 AM

      you are confused.
      do until is not evaluated until the bottom of the loop
      and
      do while is evaluated at the top of the loop

      Delete
  6. Anonymous2:44 PM

    Sakar Sham;
    So in "while" condition it checks up to 6 then it stops. We would not forget it. Thank you.

    How about if replaced by "until"? It must be in the question somewhere?

    ReplyDelete
  7. Remya9:40 AM

    Answer is D. 7

    here, note that the operator is LE (less than or equal to). So the condition is true the first time.
    Calls = 6 and it becomes Calls + 1 => 6+1 = 7.

    The loop stops executing as the value of calls becomes greater than 6. Thus, output is 7.

    ReplyDelete
  8. Remya9:48 AM

    Please note the difference between do while and do until:


    DO WHILE
    The while test is evaluated at the top of the loop.

    DO UNTIL
    The until test is evaluated at the bottom of the loop.

    Reference: http://www2.sas.com/proceedings/forum2007/067-2007.pdf

    The change should be change in the following manner to obtain the same results using a do until loop:

    data clients;
    calls = 6;
    do until (calls GE 6);
    calls + 1;
    end;
    run;

    Not that the difference here is DO WHILE uses Calls LE 6 and DO UNTIL uses Calls GE 6.

    The example provided in the reference helps understand this better.

    ReplyDelete
  9. Anonymous9:08 PM

    D, 7

    ReplyDelete
  10. Hello!! I'am glad to read the whole content of this blog and am very excited.Thank you.
    ตารางคะแนน

    ReplyDelete
  11. do while loop is looking for where to stop which is when it counters false and that is when calls +1 < 6 (simple math) and that would be when calls =7 and that should be the desired output(checking when to stop).

    ReplyDelete