Question4:ThefollowingSASprogramissubmitted:
datawork.totalsales;
setwork.monthlysales(keep=yearproductsales);
retainmonthsales{12};
arraymonthsales{12};
doi=1to12;
monthsales{i}=sales;
end;
cnt+1;
monthsales{cnt}=sales;
run;
ThedatasetnamedWORK.MONTHLYSALEShasoneobservationpermonthforeachoffiveyearsforatotalof60observations.Whichoneofthefollowingistheresultoftheabove
program?
1.Theprogramfailsexecutionduetodataerrors.
2.Theprogramfailsexecutionduetosyntaxerrors.
3.TheprogramrunswithwarningsandcreatestheWORK.TOTALSALESdatasetwith60observations.
4.TheprogramrunswithouterrorsorwarningsandcreatestheWORK.TOTALSALESdatasetwith60observations.
CorrectAnswer:2
Exp:AnswerisBbecauseretainstatementforarraysshouldlooksomethinglikeretainmonthsales1-monthsales12;
Evenifwechangeretainstatementtoproperone,programwillerrorout.Becausearrayindexwillbeoutofboundafterreading13thobservation.Belowismycodeandlogfile.
datamonthly(keep=sales);
doi=1to60;
sales=i*10;
output;
end;
run;
datawork.totalsales;
setwork.monthly(keep=sales);
retainmsales1-msales12;
arraymsales{12};
doi=1to12;
msales{i}=sales;
end;
cnt+1;
msales{cnt}=sales;
run;
ERROR:Arraysubscriptoutofrangeatline227column1.
SALES=130MSALES1=130MSALES2=130MSALES3=130MSALES4=130MSALES5=130MSALES6=130MSALES7=130MSALES8=130MSALES9=130MSALES10=130MSALES11=130MSALES12=130I=13CNT=13_ERROR_=1
_N_=13NOTE:TheSASSystemstoppedprocessingthisstepbecauseoferrors.NOTE:Therewere13observationsreadfromthedatasetWORK.MONTHLY.
WARNING:ThedatasetWORK.TOTALSALESmaybeincomplete.Whenthisstepwasstoppedtherewere12observationsand15variables.
WARNING:DatasetWORK.TOTALSALESwasnotreplacedbecausethisstepwasstopped