Hello SAS Community,
If I need the average of 3 numbers I can use
mean (number1, number2, number3)
that will give me the average of the 3 variables
If I use instead
mean (number1 + number2 + number3)
SAS will (rightly) compute the sum of the 3 numbers.
Would you consider typing
mean (number1 + number2 + number3)
if what I need is
mean (number1, number2, number3)
a LOGIC or a SYNTAX error?
Thanks in advance.
Hi @Anne_A,
without having more context, I would assume a logic error.
Best
Markus
Hi @Anne_A,
without having more context, I would assume a logic error.
Best
Markus
Thanks Markus,
So would I. The thing is, in the SAS Certified Specialist prep guide (pp 63-64), this is provided as an example of syntax error - I was puzzled hence my question.
I will keep considering this a logical error, praying for the exam questions not to be too close to the prep guide's content ... 😉.
Cheers.
If it was a syntax error, there would be errors in the LOG.
You can type all sorts of ridiculous things into SAS that will not produce errors in the log, so they are not syntax errors, but most likely they are logic errors.
But maybe the definition of "syntax error" is the human user types in the wrong code ... ? I hope not, that's what it sounds like they are looking for. Is there anywhere in the class notes that defines "syntax error"?
Thanks @PaigeMiller ,
So we all agree that this specific problem is indeed a logic error. Maybe an incomplete copy-paste-adapt step in the book.
Cheers.
@Anne_A , I took the exam early this year. I think you don't have to worry about theoretical discussions whether it's a logic or syntax error. It's a practise exam. I you know how to do the coding covered by the content guide, you will be fine.
Best Luck anyway.
Best
Markus
One thing to consider, besides basic mean , is that when you use
(number1 + number2 + number3)
The result will be missing if any of the 3 variables have a missing value.
Consider this code. Run it and compare the results of the two Vmean variables.
data example; input v1 - v3; /* function mean*/ vmean1= mean(v1,v2,v3); /* manual calculation for mean*/ vmean2= (v1 + v2 + v3) / 3; datalines; 1 2 3 1 2 . . . . ;
So which construct you might use, function vs manual calculation, may depend on the need of your code.
This is a knowledge-sharing community for SAS Certified Professionals and anyone who wants to learn more about becoming SAS Certified. Ask questions and get answers fast. Share with others who are interested in certification and who are studying for certifications.To get the most from your community experience, use these getting-started resources:
Community Do's and Don'ts
How to add SAS syntax to your post
How to get fast, helpful answers
Ready to level-up your skills? Choose your own adventure.