--------10-------20-------30
squash 1.10
apples 2.25
juice 1.69
The following SAS program is submitted using the raw data file above:
data groceries;
infile 'file-specification';
input item $ cost;
run;
Which one of the following completes the program and produces a grand total for all COST values?
A. grandtot = sum cost;
B. grandtot = sum(grandtot,cost);
C. retain grandtot 0;
grandtot = sum(grandtot,cost);
D. grandtot = sum(grandtot,cost);
output grandtot;
Click Comment link to get answer
C
ReplyDeleteterima kasin
DeleteAnswer is C
ReplyDeleteB
ReplyDeletesorry ans is C
ReplyDeleteC
ReplyDeleteAnswer is A
ReplyDeleteCan Those FUkin stupid guys who are not sure about their answers stop stupidly answering??? Those shabi answers really confused me a big lot!!!!
ReplyDeleteThose ppl don't know they are wrong until they know what is actually right. So you Mr. Asshole keep ur mouth and ass shut and type for your own self and not for others or about others. If ur problem is solved , good for you. If not, go to some other blog. We are not here for you. Infact, you are here for us seeking our help! Bingo !
DeleteU r so rude. Shame on u.
DeleteShame on you... Others are here for help, but not owe.
DeleteThis comment has been removed by the author.
DeleteBro, calm down... and are you sure they neng kan ming bai what shabi is?(huaji~)
Deletelol shabi
ReplyDeleteCan some one please explain which one is correct. thanks
ReplyDeletesum is a function which means it will need brackets () so A is not the correct answer.
ReplyDeleteThere no such variable as grandtot, so program will give syntax error, so option B and D is not the correct answer.
C is the correct option because retain statement is creating a new variable and initializing it with zero. Sum function will add cost to grandtot for each observation and as grandtot is retained it will carry forward the added value.
Hope this helps.
Nice Explanation..!! It really helpful.
DeleteThanks a lot
DeleteSum Statement
Adds the result of an expression to an accumulator variable.
Syntax
variable+expression;
variable
specifies the name of the accumulator variable, which contains a numeric value.
Tip: The variable is automatically set to 0 before SAS reads the first observation. The variable's value is retained from one iteration to the next, as if it had appeared in a RETAIN statement.
Tip: To initialize a sum variable to a value other than 0, include it in a RETAIN statement with an initial value.
expression
is any SAS expression.
Tip: The expression is evaluated and the result added to the accumulator variable.
Tip: SAS treats an expression that produces a missing value as zero.
Comparisons
The sum statement is equivalent to using the SUM function and the RETAIN statement, as shown here:
retain variable 0;
variable=sum(variable,expression);
Examples
Here are examples of sum statements that illustrate various expressions:
balance+(-debit);
sumxsq+x*x;
nx+(x ne .);
if status='ready' then OK+1;
SO BRACKETS () ARE NOT ALWAYS A NECESSITY O SUM STATEMENT
Thank you.
Deletejust stay wid yr basics......
ReplyDeletewould u get d sas software in d xam?
no ...........
to get the answer use d method of elimintaio-----
>> option B is rejected due to wrong SUM() syntax.....
>> option C is rejected due to wrong SUM() syntax also....
>>in option D totquantity is a accumulator varible, The accumulator variable starts giving missing value , when its adds up eith a missing value, so d desirerd ouptput we coulds nt get......so option D rejected....
>>option A is correct bcoz its itself creates d variable totquantity , initialises wid 0, retains its valueas after iterations , ignores miising values.......
>>> joydeep786@gmail.com
dude ... do you even SAS ??? this is the silliest explanation ... why dont you try running the code with all the answer options and then be this definitive ... the answer is C .. (btw .. the only WRONG sum syntax is in option A)
DeleteReferring to 'the basics' here, I could not find difference between the syntax of SUM() function in option C and D. So, option C can not be rejected !
ReplyDeleteD is wrong bcz output statement is not needed and also it is wrong syntax.
Answer is C according to basics even if we dnt use SAS.
data groceries;
ReplyDeleteinput item $ cost;
retain grandtot 0;
grandtot = sum(grandtot,cost);
datalines;
squash 1.10
apples 2.25
juice 1.69
;
run;
its c
It is C, but I'd like to point out in this line of code:
ReplyDeleteretain grandtot 0;
The '0' sets the initial value of grandtot to 0. This is not necessary, since gradtot doesn't already have a value assigned to it, and SAS isn't so sassy as to think you're adding to a missing value.
Answer is A, Does not make sense to have sum (grandtot cost) , it will sum grandtot and sum.
ReplyDeleteIs it not enough sum cost? Conformed the answer is A. Do not get distracted who ever said A got the right answer.
correct. Because The SUM statement prints sums for the variables in the list. It cannot be C, because we do not want cumulative figures for each obs. We just want the one grand total.
DeleteThere is not cumulative figures for each obs. That would require an explicit output; to be added.
DeleteA is the correct answer because we just want the grand total.C would give us the accumulated total.
DeleteDamn work on your logic and that will help in the exam to pass. Yeah you are right if not sure start eliminating and you will find one or two.
ReplyDeleteUse your brain and memory to eliminate the wrong one.
Clayton Roche,
ReplyDeleteIf you are correct, then both B and C are correct.
He said that '0' is not necessary, not retain statement.
Deletesab sale paglu hain...
ReplyDeleteanswer is "c"
I can't agree more with baba45! lol Paglu
ReplyDeletei am agree with baba45: sab paglu hain... answer is C
ReplyDeleteAnswer: C
ReplyDeleteMy thoughts:
A has incorrect syntax and will not compile. The idea of "sum cost" has some merit in the context of a proc print situation, but used in an assignment statement like this, it's just garbage.
B will actually perform sum(.,cost) for each iteration... assigns this result (=cost) to grandtot, so the result is that grandtot equals the newly read value of cost each time... because for each iteration grandtot is reset to missing, in the absence of a 'retain' SAS has no memory of the previous value. It compiles alright, but it doesn't produce the goods.
C works just as intended, try it and see.
D output grandtot; does NOT mean output the value of grandtot to the groceries dataset. It means send the output to a particular dataset called "grandtot". Since this dataset doesn't in fact exist, as it wasn't declared in the data statement at the top, this is a compile time error.
Nigel
baba45 zinda baad... sab paglu hain :D
ReplyDeleteC is correct PLease run these codes;
ReplyDeleteC)data groceries;
input item $ cost;
retain grandtot 0;
grandtot = sum(grandtot,cost);
cards;
squash 1.10
apples 2.25
juice 1.69
run;
D)data groceries;
input item $ cost;
grandtot = sum(grandtot,cost);
output grandtot;
cards;
squash 1.10
apples 2.25
juice 1.69
run;
There will be zero observation for D while C gives you the correct sums.
This comment has been removed by the author.
Deletethis is A
ReplyDeleteC) retain does not accept o
SUM statement does not require ( ) \
general form is sum variable; in this case the variable is costs
and grandtot is defined by the statement, it will write the output at the end of the column costs ...
The answer is C I tested all choices.
ReplyDeletedata test;
infile datalines;
input item $ cost;
grandtot = sum cost;
datalines;
squash 1.10
apples 2.25
juice 1.69
;
data test;
infile datalines;
input item $ cost;
grandtot = sum(grandtot,cost);
datalines;
squash 1.10
apples 2.25
juice 1.69
;
data test;
infile datalines;
input item $ cost;
retain grandtot 0;
grandtot = sum(grandtot,cost);
datalines;
squash 1.10
apples 2.25
juice 1.69
;
data test;
infile datalines;
input item $ cost;
grandtot = sum(grandtot,cost);
output grandtot;
datalines;
squash 1.10
apples 2.25
juice 1.69
;
C
ReplyDeleteC
ReplyDeleteIs the answer B...
ReplyDeleteHow about if there is a missing variable in the list? what would happen with the sum statement and/or the sum function?
ReplyDeleteC
ReplyDeletec
ReplyDelete