Question2:ThecontentsoftherawdatafileCALENDARarelistedbelow:
--------10-------20-------30
01012000
ThefollowingSASprogramissubmitted:
datatest;
infile'calendar';
input@1datemmddyy10.;
ifdate='01012000'dthenevent='January1st';
run;
WhichoneofthefollowingisthevalueoftheEVENTvariable?

1.01012000
2.January1st
3.(missingnumericvalue)
4.Thevaluecannotbedeterminedastheprogramfailstoexecuteduetoerrors.
CorrectAnswer4:
Exp:
FormattedinputenablesyoutosupplyspecialinstructionsintheINPUTstatementforreadingdata.Forexample,toreadnumericdatathatcontainsspecialsymbols,youneedto
supplySASwithspecialinstructionssothatitcanreadthedatacorrectly.Theseinstructions,calledinformats
datatotal_sales;
inputDatemmddyy10.+2Amountcomma5.;
Inthisexample,theMMDDYY10.informatforthevariableDatetellsSAStointerprettherawdataasamonth,day,andyear,ignoringtheslashes.TheCOMMA5.informatforthe
variableAmounttellsSAStointerprettherawdataasanumber,ignoringthecomma.The+2isapointercontrolthattellsSASwheretolookforthenextitem.
However,SASisalsocapableofreadingtwo-digityearvalues(forexample,09/05/99).Inthisexample,usetheMMDDYY8.informatforthevariableDate.
AnswerDisbecausedateconstantisinvalid.[Evernafterprovidingcorrectdateconstant-date='01JAN2000'ddesiredoutputnotproducedanditproducesNote:SASwenttoanewline
whenINPUTstatementreachedpasttheendofaline.]
Theerrorthatshownevenonyourcorrectionisprobablybecausetheinformatgiveniswrong.Theinformatshouldbe'mmddyy8.'.Onceyoudothat,theeventshowsupasJanuary1st
Ifweprovidecorrectdatecontantdate='01jan2000'd,willgettheresult.
pleasetrythebelowprogram.
datatest;
infiledatalines;
input@1datemmddyy10.;
ifdate='01jan2000'dthenevent='January1st';
datalines;
01012000
;