Base SAS Certification Questions and important concepts needed to ace the exams.
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
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..
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!
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.
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.
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. ( खेल खतम पैसे ह्जम ).
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
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
C
ReplyDelete+
Delete+
C
ReplyDeletewhy ? D
ReplyDeleteD, 7 gt 6, so 7+1=8
ReplyDeleteTake the code and test it. The answer is 7
ReplyDeleteC
ReplyDeleteCan someone explains....the condition says prod > 6 ...which is not true...but until statement even runs once for false statement too...???
ReplyDeleterun the below code, u will understand how it works.
Deletedata 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..
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!
ReplyDeleteBecause of prod + 1 statement, SAS compiler will assume a retain prod 0; statement.
ReplyDeleteFirst 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.
data work.sets;
Deletedo until (prod gt 6);
prod + 3;
end;
run;
In this case output is coming as 9, how you can apply the same logic here.......??
1st loop - prod=3 -> 3 gt 6 -> false,loop continue
Delete2nd 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.
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.
ReplyDeleteans d
ReplyDeleteA 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.
If you run the SAS code:
ReplyDeletedata work.sets;
do until (prod gt 6);
prod + 1;
end;
run;
Value of prod=7, 'C'.
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...
ReplyDeletebut prod is still 7.
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
ReplyDeleteOnce guy used to say, ounce of memory is better than tons of logic( CPA Exam)
ReplyDeleteBut 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. ( खेल खतम पैसे ह्जम ).
But it never hits 7.
DeleteSince 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.
ReplyDeletec
ReplyDeleteHey 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.
ReplyDeletePlease 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
7
ReplyDelete?
ReplyDeleteVery useful blog and very informative article thank you sharing keep posting sas training, sas admin training, sas clinical training,sas platformadmin training
ReplyDeleteC?
ReplyDeleteTry this one.
ReplyDeletedata work.sets;
do until (prod gt 6);
prod = prod + 1;
end;
run;
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.
ReplyDeleteso 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
C
ReplyDeleteCan anyone please explain prod gt 6 condition?
ReplyDelete