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
The answer is D
ReplyDeleteAnswer is D, will not execute because of errors.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteanswer D
ReplyDeleteAnswer 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.]
ReplyDeleteShiva,
ReplyDeleteThe 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
Answer is D. If we provide correct date contant date='01jan2000'd, will get the result.
ReplyDeleteplease try the below program.
data test;
infile datalines;
input @1 date mmddyy10.;
if date = '01jan2000'd then event = 'January 1st';
datalines;
01012000
;
sweta....try i twith date='01012000' and still u get the result , tha answer should be b
ReplyDeleteThe answer should be B. try this program:
ReplyDeletedata test;
infile datalines;
input @1 date mmddyy8.;
if date = '01012000'd then event = 'January 1st';
datalines;
01012000
;
proc print;
run;
Answer is D. because question mentions date constant ( Notice d). Not just '01012000'.
ReplyDeleteans is D that because 01012000 is changed to its default sas date so when we assign '01012000'd it take it as invalid format...
ReplyDeletethe answer should be B.
ReplyDeleteTry this,
data test;
infile 'calendar';
input @1 date mmddyy10.;
if date = '01012000'd then event = 'January 1st';
proc print;run;
answer is D.
ReplyDeleteSyntax error due to incorrect format fails to execute "D" finals answer.
ReplyDeleteSakar Sham
But in the log it does not say syntax error?
ReplyDeleteAniket , 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!
data test6;
ReplyDeleteinfile '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.
answer is B
ReplyDeleteAnswer is B, run the below code, you will get correct answer
ReplyDeletedata test;
input @1 date mmddyy10.;
if date = '01012000'd then event = 'January 1st';
datalines;
01012000
;
run;
proc print;
run;
Sorry Answer is D, ignore the above answer posted by me
ReplyDeletefollowing error appears in the log:
Invalid date/time/datetime constant '01012000'd.
Invalid number conversion on '01012000'd.
Karel;
ReplyDeleteIf 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;