Question 4 : The following SAS program is submitted:
data work.totalsales;
set work.monthlysales(keep = year product sales);
retain monthsales {12} ;
array monthsales {12} ;
do i = 1 to 12;
monthsales{i} = sales;
cnt + 1;
monthsales{cnt} = sales;
The data set named WORK.MONTHLYSALES has one observation per month for each of five years for a total of 60 observations. Which one of the following is the result of the above program?

1. The program fails execution due to data errors.
2. The program fails execution due to syntax errors.
3. The program runs with warnings and creates the WORK.TOTALSALES data set with 60 observations.
4. The program runs without errors or warnings and creates the WORK.TOTALSALES data set with 60 observations.

Correct Answer : 2
Exp : Answer is B because retain statement for arrays should look something like retain monthsales1-monthsales12;
Even if we change retain statement to proper one, program will error out. Because array index will be out of bound after reading 13th observation. Below is my code and log file.

data monthly (keep = sales);
do i = 1 to 60;
sales = i*10;
data work.totalsales;
set work.monthly(keep = sales);
retain msales1-msales12 ;
array msales {12} ;
do i = 1 to 12;
msales{i} = sales;
cnt + 1;
msales{cnt} = sales;
ERROR: Array subscript out of range at line 227 column 1.
SALES=130 MSALES1=130 MSALES2=130 MSALES3=130 MSALES4=130 MSALES5=130 MSALES6=130 MSALES7=130 MSALES8=130 MSALES9=130 MSALES10=130 MSALES11=130 MSALES12=130 I=13 CNT=13 _ERROR_=1
_N_=13 NOTE: The SAS System stopped processing this step because of errors. NOTE: There were 13 observations read from the data set WORK.MONTHLY.
WARNING: The data set WORK.TOTALSALES may be incomplete. When this step was stopped there were 12 observations and 15 variables.
WARNING: Data set WORK.TOTALSALES was not replaced because this step was stopped