The SAS data set named WORK.TEST is listed below:
capacity airplanetype staff
150 Large 10
Which one of the following SAS programs created this data set?
A. data work.test;
capacity = 150;
if 100 le capacity le 200 then
airplanetype = 'Large' and staff = 10;
else airplanetype = 'Small' and staff = 5;
run;
B. data work.test;
capacity = 150;
if 100 le capacity le 200 then
do;
airplanetype = 'Large';
staff = 10;
end;
else
do;
airplanetype = 'Small';
staff = 5;
end;
run;
C. data work.test;
capacity = 150;
if 100 le capacity le 200 then
do;
airplanetype = 'Large';
staff = 10;
else
do;
airplanetype = 'Small';
staff = 5;
end;
run;
D. data work.test;
capacity = 150;
if 100 le capacity le 200 then;
airplanetype = 'Small';
staff = 5;
else;
airplanetype = 'Large';
staff = 10;
run;
Click Comment link to get answer
B
ReplyDeletewhat about A?
ReplyDeleteif ....and.....then....
Deletewe cannot do:
if ....then ....and...
("and" is basically used to connect two clauses)
B is the correct answer.
Deleteif a then b and c;
ReplyDeleteIt seems that only b will be carried out.
Defintely B
ReplyDeleteIn A you have tis line in error
ReplyDeleteairplanetype = 'Large' and staff = 10;
In C you have a Structure Problem
and In D the condition is reverse
So the answer is B
could u pls explain why the error is occuring in A
ReplyDeleteSee highligted are the mistakes and B choice has no errors so it is the correct choice.
ReplyDeleteA. data work.test;
capacity = 150;
if 100 le capacity le 200 then
airplanetype = 'Large' and staff = 10;
else airplanetype = 'Small' and staff = 5;
run;
B. data work.test;
capacity = 150;
if 100 le capacity le 200 then
do;
airplanetype = 'Large';
staff = 10;
end;
else
do;
airplanetype = 'Small';
staff = 5;
end;
run;
C. data work.test;
capacity = 150;
if 100 le capacity le 200 then
do;
airplanetype = 'Large';
staff = 10;
else /*end missing for if do loop*/
do;
airplanetype = 'Small';
staff = 5;
end;
run;
D. data work.test;
capacity = 150;
if 100 le capacity le 200 then;
airplanetype = 'Small';
staff = 5;
else; /* there is no if associated with this else */
airplanetype = 'Large';
staff = 10;
run;
Good explanation vikas
Deletethanks
Thanks! very helpful
DeleteAnswer is B
ReplyDeletereason:
If we would perform more than one action under an if statement, we should use do-end loop whithin.
Understand that correct answer is B by POE, thank you. However, could someone explain why A gives this output:
ReplyDeletecapacity airplanetype staff
150 0 .
I think each do loops needed an END statement c - is not a correct answer.
ReplyDeleteA : "and" does not execute it?
Guys;
ReplyDeleteYou will not sas program to run in Exam, some one said right, use your head and do the elimination process and choose one is correct then put it in program and conform your logic.
We want to hear and share the logic not only the right answer, we can do that too.
Am I right?
Folks, in A. airplane = 'Large' and staff = 10 is the culprit.
ReplyDeleteBoth statement has to be satisfied together therefore answer B has separated and in two statement and that is the one we are going to choose.
Peace .
Guddu;
ReplyDeleteIn exam you are not going to run this program and get the right answer.
We can run and get the answer too.
Give us the right logic behind it and we are not trying to memories it. What if they do little change on the same question but we have to choose the different answer.
woudl A work if it had ()?
ReplyDeletedata work.test;
capacity = 150;
if 100 le capacity le 200 then
(airplanetype = 'Large' and staff = 10);
else (airplanetype = 'Small' and staff = 5);
run;
Thx in advance.
your code is correct, i run it in SAS
Deletewithin if loop we can assign only one task. therefore if we want more than one task either calculation/creating variable/assigning value we use DO-END loop. hence answer is b
ReplyDeleteFinally. Thank you.
DeleteAny time you have more than 1 things to do , then use do loop and need to end with end ; that is why b is option; C also looks same but is not the right ans becoz missing end in do loop. A is not ans as it is missing do loop.
DeleteB
ReplyDeleteB
ReplyDeleteIs there something comparable to this blog for advanced certification preparation?
ReplyDelete
ReplyDeleteThis Is Really Useful And Nice Information. ราคาบอล
This are such great articles. ราคาบอล This articles can help you to make some new ideas.
https://sakukrub98.hatenablog.com/entry/2020/08/19/121317?_ga=2.74836054.594202270.1597630955-1286484823.1596077192 I appreciate for reading my blogs.