ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 35

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

17 comments:

  1. Anonymous1:40 PM

    ANSWER IS C FOR SURE

    ReplyDelete
  2. how it is C ? can u expalain?

    ReplyDelete
    Replies
    1. Similar to last question, DO WHILE (evaluates at the top of the loop). [Remember: SAS gives value starting from 0, if value not defined] n=0, 1, 2, 3, 4, 5 than n is lt (less than) 6 therefore n lt 6 is TRUE. DO LOOP is executed.
      Adding plus 1 at every iteration.
      Now, when n=6 at top, it is not less than 6 therefore condition n lt 6 is FALSE. DO LOOP is not executed.
      Hence, the value of n remains 6

      Delete
  3. Anonymous3:15 PM

    because of n+1 statement we assume a implicit retain n 0; statment.
    First loop (0 lt 6) => true => n = 1
    Second loop (1 lt 6) => true => n= 2
    ......
    last loop (6 lt 6) => false => do while exits and pdv writes 6 as value of n in output dataset. Hopefully that helps.

    ReplyDelete
  4. aniket...ani....2:44 PM

    c carefully.....
    ans is c-6.

    data pieces;
    do while (n lt 6);
    n + 1;
    end;
    run;
    proc print data=pieces;
    run;
    it will take n as 1 and loop 5 times to get 5 which is less then 6. then add 5+1=6.
    put 4 inplace of 1 n c u will get 8 that becose it loops once n give 4 so 4+4 gives 8
    put 2 inplace of 1 n c. it will loop twice to give 4 and 4+2 is 6 so ans is 6 .. i am great na...

    ReplyDelete
  5. Anonymous3:03 PM

    Folks:

    In question (34)
    calls= 6;
    do while ( call le 6)
    calls+1
    end;
    run;
    in Question (35)
    do while (n lt 6);
    n + 1;
    end;
    run;
    Please someone explain the differences?
    in Q 34 , calls= 6 and when it reads calls takes the value 6 and adds 1 gives us the result 7, no more do loops stops there because in next iteration calls will be greater than 6.a Am I correct?
    but in Q35 n is not given rather it is in the do loops and reads 5 and adds 1 = 6, next loop it is equal to 6, stops the iteration. VOILA!!!!!!!!,
    Please correct me if I am wrong.

    ReplyDelete
  6. Anonymous9:21 PM

    lt = "less than"

    le = "less than or equal to"

    ReplyDelete
  7. The ans is 6 (C) in this case. Nice expln given by some one already abt implicit retain as n+1

    ReplyDelete
  8. This is just the information I am finding everywhere. Thanks for your blog, I just subscribe your blog. This is a nice blog..
    50 Niche Relevant Blog Comment High Quality

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

    ReplyDelete
  10. All you need to be aware in this case is knowing the following difference:

    lt means 'less than <'
    le means 'less or equal to <='

    same can be said for > , >=
    gt ' greater than'
    ge 'greater than or equal to'.

    Hope it helps

    ReplyDelete