The following SAS program is submitted:
data work.january;
set work.allmonths (keep = product month num_sold cost);
if month = 'Jan' then output work.january;
sales = cost * num_sold;
keep = product sales;
run;
Which variables does the WORK.JANUARY data set contain?
A. PRODUCT and SALES only
B. PRODUCT, MONTH, NUM_SOLD and COST only
C. PRODUCT, SALES, MONTH, NUM_SOLD and COST only
D. An incomplete output data set is created due to syntax errors.
Click Comment link to get answer
The answer is D
ReplyDeleteThe answer is D.
ReplyDeleteAs there is syntax error.
"keep = product sales" which is the incorrect way to use KEEP option.
Answer D
ReplyDeleteCorrect Answer is D
ReplyDeleteSharad, Not Keep option, Keep statement
ReplyDeleteIt creates a variable named keep also!. It is not a mistake to put keep=something because SAS takes it as a new variable
ReplyDeleteBut Andrea here it is
ReplyDeleteKeep = Product sales;
Keep=options is used in an inappropriate place
ReplyDeletethe correct answer is D. Some syntax errors during data step will not stop execution.
ReplyDeletethe keep statement don't need '='
ReplyDeleteI think the answer should be B.
ReplyDeleteThere is no syntax error with the Keep=.
Can the admin plz confirm the right answer?
try to run the program in SAS and you will know that answer is D.
ReplyDeleteSakar Sham:
ReplyDeleteGuys Correct answer is "D", but wanted to read logic. If we see similar question, can come to a logic.
It has syntax error is it due to
1) if month = 'Jan' then output work.january; or
2) keep = product sales;
For sure if it is with data line ( drop = variables) and no need = in the body separately.
I have never read any statement like in (1), output is a data set, which one is the reason? or both are the reasons?
Your logic is appreciated?
the mistake is in conditional statement..
ReplyDeleteit is already creating datastep tht is january in first statement and also creating in if statement so there is syntax error...so answer is D
Nehal;
ReplyDeleteWe agreed the syntax error ? Can any body be precise and hit the bulls eye? As sakar said , in the body there is no need for " = ' sign for drop or keep onless it is in data statement.If that is not the reason , can you give us your logic?
thank you.
Thank you.Andrea! I got the reason clearly, sakar was not clear, though he had good point and elaborated it.
ReplyDeleteif we have a statement keep = variables, then SAS is looking for new variables, does it encounters with previous variables and gives the syntax error? Can you elaborate more?
The right answer is B.In order for a keep statement to be used in a data step,it is stated as Keep product sales and not Keep = product sales.Here keep= product sales is like an assignment statement.
ReplyDeleteThe answer is B for the same reason mentioned above! Since the syntax error occurs after january dataset is created, the dataset will be created and the log will display a syntax error like this (An example):
ReplyDelete303 keep = years years_service;
----
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
304 run;
No, the correct answer is D as the program expects an operator between the two variables in the keep = statement.
ReplyDeleteAnswer is D cuz here assignment statement is used after output,
ReplyDeleteD IS CORRECT
ReplyDeletedata work.january;
5 set work.allmonths (keep = product month num_sold cost);
6 if month = 'Jan' then output work.january;
7 sales = cost * num_sold;
8 keep = product sales;
-----
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ,
GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.
9 run;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
8:8
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.JANUARY may be incomplete. When this step was stopped there were 0 observations and 6
variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.01 seconds