Base SAS 11

The contents of the raw data file CALENDAR are listed below:
--------10-------20-------30
01012000
The following SAS program is submitted:
data test;
infile 'calendar';
input @1 date mmddyy10.;
if date = '01012000'd then event = 'January 1st';
run;
Which one of the following is the value of the EVENT variable?
A. 01012000
B. January 1st
C. . (missing numeric value)
D. The value can not be determined as the program fails to execute due to errors.Click Comment link to get answer

20 comments:

  1. The answer is D

    ReplyDelete
  2. Answer is D, will not execute because of errors.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Answer D is becaues date constant is invalid. [Evern after providing correct date constant -date='01JAN2000'd desired output not produced and it produces Note: SAS went to a new line when INPUT statement reached past the end of a line.]

    ReplyDelete
  5. Shiva,

    The error thats shown even on your correction is probably because the informat given is wrong. The informat should be 'mmddyy8.'. Once u do that, the event shows up as January 1st

    ReplyDelete
  6. Answer is D. If we provide correct date contant date='01jan2000'd, will get the result.
    please try the below program.

    data test;
    infile datalines;
    input @1 date mmddyy10.;
    if date = '01jan2000'd then event = 'January 1st';
    datalines;
    01012000
    ;

    ReplyDelete
  7. sweta....try i twith date='01012000' and still u get the result , tha answer should be b

    ReplyDelete
  8. The answer should be B. try this program:

    data test;
    infile datalines;
    input @1 date mmddyy8.;
    if date = '01012000'd then event = 'January 1st';
    datalines;
    01012000
    ;
    proc print;
    run;

    ReplyDelete
  9. Answer is D. because question mentions date constant ( Notice d). Not just '01012000'.

    ReplyDelete
  10. ans is D that because 01012000 is changed to its default sas date so when we assign '01012000'd it take it as invalid format...

    ReplyDelete
  11. the answer should be B.
    Try this,
    data test;
    infile 'calendar';
    input @1 date mmddyy10.;
    if date = '01012000'd then event = 'January 1st';
    proc print;run;

    ReplyDelete
  12. answer is D.

    ReplyDelete
  13. Syntax error due to incorrect format fails to execute "D" finals answer.

    Sakar Sham

    ReplyDelete
  14. But in the log it does not say syntax error?

    Aniket , your are right if we take the d out from the statement then it will give this;

    obs date event
    1 14610

    that d is the culprit for error!

    ReplyDelete
  15. data test6;
    infile 'FILENAME';
    input @1 date mmddyy8.;
    if date = '01012000' then event = 'January 1st';
    run;

    Output: 14610 - runs without error but not what we want.

    data test6;
    infile 'FILENAME';
    input @1 date $; *or numeric input @1 date;
    if date = '01012000' then event = 'January 1st';
    run;
    Output: date = 01012000 and event = January 1st

    Both of the above run without errors.

    ReplyDelete
  16. Answer is B, run the below code, you will get correct answer
    data test;
    input @1 date mmddyy10.;
    if date = '01012000'd then event = 'January 1st';
    datalines;
    01012000
    ;
    run;
    proc print;
    run;

    ReplyDelete
  17. Sorry Answer is D, ignore the above answer posted by me
    following error appears in the log:
    Invalid date/time/datetime constant '01012000'd.
    Invalid number conversion on '01012000'd.

    ReplyDelete
  18. Karel;

    If instead of '01012000'd there was standing '01JAN2000'd, the program would have worked with event being January 1st, but with the original notation it doesn't.
    --> Answer D is correct.

    Try this:

    data test;
    infile datalines;
    input @1 date mmddyy10.;
    if date = '01JAN2000'd then event = 'January 1st';
    datalines;
    01012000
    ;
    proc print;
    run;

    ReplyDelete