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;
end;
cnt + 1;
monthsales{cnt} = sales;
run;
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?
A. The program fails execution due to data errors.
B. The program fails execution due to syntax errors.
C. The program runs with warnings and creates the WORK.TOTALSALES data set with 60 observations.
D. The program runs without errors or warnings and creates the WORK.TOTALSALES data set with 60 observations.Click Comment link to get answer
Answer is B because retain statement for arrays should look something like retain monthsales1-monthsales12;
ReplyDeleteEven 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;
output;
end;
run;
data work.totalsales;
set work.monthly(keep = sales);
retain msales1-msales12 ;
array msales {12} ;
do i = 1 to 12;
msales{i} = sales;
end;
cnt + 1;
msales{cnt} = sales;
run;
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.
since the loop is mentioned to move till 12 then why will it try to execute for 13th as well...my question is even if we correct the retain statement why does the program fail
DeleteIf you observe the program failed at SALES=130, which is 13th record.
Deleteafter 12th iteration, the DO loop will increment I by 1 and check the DO loop. If fails and comes out of loop.
CNT is incremented by 1 for each record it read, so the value of CNT will be 13.
since array exceed the limit, msales{CNT} it fails.
Answer B
ReplyDeleteThe answer id B
ReplyDeletedata work.totalsales;
ReplyDeleteset work.monthly(keep = sales);
retain monthsales1-monthsales12 ;
array monthsales {60} ;
do i = 1 to 12;
monthsales{i} = sales;
end;
cnt + 1;
monthsales{cnt} = sales;
run;
proc contents data=totalsales; run;
bcoz do loop syntax is DO I=1 TO N
ReplyDeleteI+;
END;
KEEP statement has = sign
ReplyDeleteKeep Statement comes with =
ReplyDeletehttp://support.sas.com/documentation/cdl/en/lrcon/62753/HTML/default/viewer.htm#n1g8q3l1j2z1hjn1gj1hln0ci5gn.htm
ReplyDeletecheck out for types of errors in SAS
Answer is B
ReplyDeleteAnswer: B
ReplyDeleteTry the Base SAS Certification question at the link below for extra practice...good luck!
http://sascert3.blogspot.com/2013/04/base-sas-certification-example-question_9.html
-SAS Cert
why would someone ever want to use a RETAIN statement with an array?
ReplyDeleteI was wondering the exact same thing
DeleteGood Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
ReplyDeleteSAS Online Training
Did you know that you can shorten your long urls with Shortest and make cash from every click on your shortened links.
ReplyDeletegclub
gclub casino online
Interesting blog which attracted me more.Spend a worthful time.keep updating more.
ReplyDeleteSAS Training in Chennai
Here i had read the content you had posted. It is much interesting so please keep update like this.
ReplyDeleteHadoop Training in Chennai
Base SAS Training in Chennai
MSBI Training in Chennai
This comment has been removed by the author.
ReplyDeleteGSET Result 2018 is going to announce as expected very soon on official website, Check Gujarat SET Result Answer Key Merit List & Cut Off Marks Subject Wise.
ReplyDeleteThank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
ReplyDeleteSAS Data Analytics Training with Placement Support
Thanks for posting this blog, i am very impressed with your blog and it is very useful for me and other. Please visit at "Product Safety International Certification Services in UL, CE New Zealand.", i hope it be prove useful for you.
ReplyDeleteVisit Here - http://certifyme.co.nz
Thanks Regards,,,
We are urgently in need of Kidney donors with the sum of $500,000.00,WHATSAP: +91 91082 56518
ReplyDeleteEmail: : customercareunitplc@gmail.com