ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 116

The following SAS program is submitted:
data work.sets;
do until (prod gt 6);
prod + 1;
end;
run;
Which one of the following is the value of the variable PROD in the output data set?
A. 5
B. 6
C. 7
D. 8
Click Comment link to get answer

31 comments:

  1. Anonymous2:45 PM

    why ? D

    ReplyDelete
  2. Anonymous2:39 PM

    D, 7 gt 6, so 7+1=8

    ReplyDelete
  3. Take the code and test it. The answer is 7

    ReplyDelete
  4. Can someone explains....the condition says prod > 6 ...which is not true...but until statement even runs once for false statement too...???

    ReplyDelete
    Replies
    1. Anonymous4:16 PM

      run the below code, u will understand how it works.
      data x;
      do until (prod gt 6);
      j=prod;
      prod + 1;
      output;
      end;
      run;
      The variable j represents the real value of prod while the 'Until' condition is applied..

      Delete
  5. Anonymous7:11 PM

    I don't understand. Var prod is not initialized, nor is there an assign statement in the do-until loop for prod. I believe, when prod is encountered first, it is given a missing value. So, because of the above reasoning, it will stay missing and the do-until will never end!

    ReplyDelete
  6. Anonymous8:53 AM

    Because of prod + 1 statement, SAS compiler will assume a retain prod 0; statement.
    First loop => prod = 1 => (1 gt 6) => false, loop continues

    Second loop => prod = 2 => (2 gt 6) => false, loop continues

    .....

    last loop => prod = 7 => (7 gt 6) => true, do until loop exits and pdv writes prod value of 7 to output dataset.

    ReplyDelete
    Replies
    1. data work.sets;
      do until (prod gt 6);
      prod + 3;
      end;
      run;

      In this case output is coming as 9, how you can apply the same logic here.......??

      Delete
    2. 1st loop - prod=3 -> 3 gt 6 -> false,loop continue
      2nd loop -> prod=6 -> 6 gt 6 -> false, loop continue
      3rd loop-> prod=9 -> 9 gt 6-> true and the DoUntil loop exit and write 9 to output dataset.

      correct me if I am wrong.

      Delete
  7. Anonymous2:07 PM

    do until loop will execute once no matter what is the result of prod gt 6 condition. Also do until will check for condition at end of the loop. Now with this knowledge read the above answer.

    ReplyDelete
  8. Anonymous1:37 PM

    ans d

    A DO UNTIL loop always executes at least once because the condition is not
    evaluated until the bottom of the loop. In the SAS program above, the value of
    Products is incremented from 7 to 8 on the first iteration of the DO UNTIL loop,
    before the condition is checked. Therefore the value of Products is 8.

    ReplyDelete
  9. Anonymous10:41 AM

    If you run the SAS code:

    data work.sets;
    do until (prod gt 6);
    prod + 1;
    end;
    run;

    Value of prod=7, 'C'.

    ReplyDelete
  10. Product equals to 7 when you run the program...but i do not understand after prod > 6 which is =7 .....prod + 1 should be 8...
    but prod is still 7.

    ReplyDelete
  11. Anonymous7:28 PM

    Since it says do until prod gt 6 which means once prod hits 7 it does not perform prod + 1 anymore. hence the answer is 7

    ReplyDelete
  12. Anonymous12:59 PM

    Once guy used to say, ounce of memory is better than tons of logic( CPA Exam)

    But in SAS it is vise verse. We have to use the logic that works in sas but not how it works in daily life. That dude is correct.
    Once it hits the 7 the execution is finished and the iteration writes the number in program data vector 7.
    End of the story. ( खेल खतम पैसे ह्जम ).

    ReplyDelete
    Replies
    1. Anonymous9:22 PM

      But it never hits 7.

      Delete
  13. Anonymous7:58 PM

    Since do until checks the condition at the bottom of the loop, when prod + 1 becomes 7 it exits the loop and outputs 7 as the value for prod.

    ReplyDelete
  14. Anonymous4:28 PM

    Hey guys, answer is C. Until condition never cross the value 6. This loop works until it reaches only 6. However, '1' gets added in the same loop so, the final value will be 7.
    Please run the below code to get the real value of 'Prod' while each condition in the loop is being executed.
    data x;
    do until (prod gt 6);
    j=prod;
    prod + 1;
    output;
    end;
    run;
    J represents the real value of 'Prod' while the loop happening..
    Hope dis not too much of gyan..lol

    ReplyDelete
  15. Very useful blog and very informative article thank you sharing keep posting sas training, sas admin training, sas clinical training,sas platformadmin training

    ReplyDelete
  16. Anonymous9:19 PM

    Try this one.

    data work.sets;
    do until (prod gt 6);
    prod = prod + 1;
    end;
    run;

    ReplyDelete
  17. prod = prod + 1 ; this is for the iterations to move forward and not for the output, if we do not include this the program will always be running.

    so when prod = 0 < 6 it will execute,
    then prod = 1 < 6 it will execute,
    till prod = 7 > 6; at this time do until will come into play, from there it will directly run and will not execute prod = prod +1 because the condition is already satisfied.
    so the value will be 7 , Answer is C

    ReplyDelete
  18. Anonymous4:53 AM

    Can anyone please explain prod gt 6 condition?

    ReplyDelete