Base SAS 10

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

21 comments:

  1. The answer is D

    ReplyDelete
  2. The answer is D.
    As there is syntax error.
    "keep = product sales" which is the incorrect way to use KEEP option.

    ReplyDelete
  3. Correct Answer is D

    ReplyDelete
  4. Sharad, Not Keep option, Keep statement

    ReplyDelete
  5. It creates a variable named keep also!. It is not a mistake to put keep=something because SAS takes it as a new variable

    ReplyDelete
  6. But Andrea here it is

    Keep = Product sales;

    ReplyDelete
  7. Keep=options is used in an inappropriate place

    ReplyDelete
  8. the correct answer is D. Some syntax errors during data step will not stop execution.

    ReplyDelete
  9. the keep statement don't need '='

    ReplyDelete
  10. I think the answer should be B.
    There is no syntax error with the Keep=.

    Can the admin plz confirm the right answer?

    ReplyDelete
  11. try to run the program in SAS and you will know that answer is D.

    ReplyDelete
  12. Sakar Sham:

    Guys 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?

    ReplyDelete
  13. the mistake is in conditional statement..
    it 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

    ReplyDelete
  14. Nehal;
    We 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.

    ReplyDelete
  15. Thank you.Andrea! I got the reason clearly, sakar was not clear, though he had good point and elaborated it.

    if 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?

    ReplyDelete
  16. 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.

    ReplyDelete
  17. The 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):

    303 keep = years years_service;
    ----
    180

    ERROR 180-322: Statement is not valid or it is used out of proper order.

    304 run;

    ReplyDelete
  18. No, the correct answer is D as the program expects an operator between the two variables in the keep = statement.

    ReplyDelete
  19. Answer is D cuz here assignment statement is used after output,

    ReplyDelete
  20. D IS CORRECT

    data 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

    ReplyDelete