ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 9

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

23 comments:

  1. Anonymous12:41 PM

    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;
    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.

    ReplyDelete
    Replies
    1. Anonymous9:58 PM

      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

      Delete
    2. Anonymous2:37 PM

      If you observe the program failed at SALES=130, which is 13th record.
      after 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.

      Delete
  2. swapna7:15 PM

    The answer id B

    ReplyDelete
  3. MAdhuri Aswlae11:10 AM

    data work.totalsales;
    set 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;

    ReplyDelete
  4. Anonymous7:50 PM

    bcoz do loop syntax is DO I=1 TO N
    I+;
    END;

    ReplyDelete
  5. Anonymous8:03 PM

    KEEP statement has = sign

    ReplyDelete
  6. Keep Statement comes with =

    ReplyDelete
  7. Anonymous7:31 AM

    http://support.sas.com/documentation/cdl/en/lrcon/62753/HTML/default/viewer.htm#n1g8q3l1j2z1hjn1gj1hln0ci5gn.htm

    check out for types of errors in SAS

    ReplyDelete
  8. Anonymous2:46 PM

    Answer is B

    ReplyDelete
  9. Answer: B

    Try 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

    ReplyDelete
  10. Anonymous9:01 PM

    why would someone ever want to use a RETAIN statement with an array?

    ReplyDelete
    Replies
    1. Anonymous2:55 AM

      I was wondering the exact same thing

      Delete
  11. Good 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…
    SAS Online Training

    ReplyDelete
  12. Did you know that you can shorten your long urls with Shortest and make cash from every click on your shortened links.
    gclub
    gclub casino online

    ReplyDelete
  13. Interesting blog which attracted me more.Spend a worthful time.keep updating more.
    SAS Training in Chennai

    ReplyDelete
  14. Here i had read the content you had posted. It is much interesting so please keep update like this.

    Hadoop Training in Chennai

    Base SAS Training in Chennai

    MSBI Training in Chennai

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. GSET 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.

    ReplyDelete
  17. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    SAS Data Analytics Training with Placement Support

    ReplyDelete
  18. 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.

    Visit Here - http://certifyme.co.nz

    Thanks Regards,,,

    ReplyDelete
  19. Anonymous9:34 AM

    We are urgently in need of Kidney donors with the sum of $500,000.00,WHATSAP: +91 91082 56518
    Email: : customercareunitplc@gmail.com

    ReplyDelete