Fundamentals of Programming in SAS. James Blum

Читать онлайн книгу.

Fundamentals of Programming in SAS - James Blum


Скачать книгу
stores listed in the path, submit the statement:

      ods path show;

      The template store(s) named in other ODS PATH statements appear in this list shown in the SAS log if they were correctly assigned. These two statements appear in the code given for every chapter of this book.

      To see a list of templates available in any template store, a variation on the PROC TEMPLATE code given in Chapter Note 8 is given.

      proc template;

      list / store=BookData.Template;

      run;

      Finally, to use the style template with any ODS file destination (assuming all previous steps are functional), use STYLE=CustomSapphire, similar to the use of STYLE=Journal in Program 1.5.4.

      10. Valid Variable and Other Names. For most of the activities in this book, the naming conventions described in Section 1.6.2 apply. However, since SAS can connect to other data sources have different naming conventions, there are times when it is advantageous to alter these conventions. The VALIDVARNAME= system option allows for different rules to be enacted for variable names, while the VALIDMEMNAME= option allows for altering the naming conventions for data sets and data views. These are taken up in Section 7.6, which covers connections to Microsoft Excel workbooks and Access databases, which have different naming conventions than SAS.

      Concepts: Multiple Choice

      1. Using the default rules for naming in SAS, which of the following is a valid library reference?

      a. ST445Data

      b. _LIB_

      c. My-Data

      d. 445Data

      2. Which of the following is not a syntax error?

      a. Misspelling a keyword like PROC as PORC

      b. Misspelling a variable name like TypeB as TypB

      c. Omitting a semicolon at the end of a RUN statement

      d. Forgetting to close the quotation marks around the path in the LIBNAME statement

      3. Which of the following is a temporary data set?

      a. Work.Employees

      b. Employees.Work

      c. Temp.Employees

      d. Employees.Temp

      4. Using the default rules for naming data sets in SAS, which of the following cannot be used when naming a data set?

      a. Capital letters

      b. Digits

      c. Dashes

      d. Underscores

      5. What statement is necessary to produce the following information?

      Output Added:

      -------------

      Name: Report

      Label:

      Data Name: ProcReportTable

      Path: Report.Report.Report

      a. ODS RTF;

      b. ODS PDF;

      c. ODS TRACE ON;

      d. ODS LISTING;

      Concepts: Short Answer

      1. Under standard SAS naming conventions, decide whether each of the following names is legal syntax when used as a:

      i. Library reference

      ii. Data set name

      iii. Variable name

       Provide justification for each answer.

      a. mydata

      b. myvariable

      c. mylibrary

      d. left2right

      e. left-2-right

      f. house2

      g. 2nd_house

      h. _2nd

      2. Classify each of the following statements as: always true, sometimes true, or never true. Provide justification for each answer.

      a. An error message in the log is an indication of a syntax error.

      b. A warning message in the log is an indication of a logic error.

      c. Notes in the log provide details about successful code execution.

      d. Checking the log only for errors and warnings is considered a good programming practice.

      3. Classify each of the following statements as: always true, sometimes true, or never true. Provide justification for each answer.

      a. SAS data sets can contain only numeric and character variables.

      b. If the library is omitted from a SAS data set reference, the Work library is assumed.

      c. Once a library is assigned in a SAS session, it is available automatically in subsequent SAS sessions on that machine.

      d. A library and a data set can have the same name.

      4. Classify each of the following statements as: always true, sometimes true, or never true. Provide justification for each answer.

      a. A PROC step can be nested with a DATA step.

      b. The RUN statement must be used as a step boundary at the end of a DATA or PROC step.

      c. It is a good programming practice to use an explicit step boundary, such as the RUN statement, at the end of any DATA or PROC step.

      d. Global statements can be included inside DATA or PROC steps.

      5. Consider the program below.

      options date label;

      title ‘Superhero Profile: Jennie Blockhus’;

      proc print data = superheroes label;

       where homeTown eq ‘Redmond’ and current = ‘Themyscira’;

       var Alias Powers FirstIssue Superfriend Nemesis;

      run;

      options nonumber nolabel;

      proc freq data = superheroes;

       where homeTown eq “Redmond” and current = “Themyscira”;

       table sightings*state;

      run;

      a. Determine the number of global statements.

      b. Determine the number of steps.

      c. What distinguishes global statements from other statements in the above program?

      d. Is it a syntax error to enclose literals in both single and double quotation marks as done in the above program? Why or why not?

      Programming Basics

      1. Complete the following steps, in either the SAS windowing environment or SAS University Edition:

      a. Open Program 1.8.1 (shown below).

      b. Download the data for the textbook and assign a library to its location.

      c. Replace the comment with the library reference established in part (b).

      d. Submit the code.

      e. If the submission does not execute successfully, check the log and output for errors in the library assignment and/or reference.

      f. Repeat the above steps as necessary until the code executes properly.

      Program 1.8.1: Sample Program for Submission

      proc means data=/*put library reference here*/.IPUMS2005Basic;

      class MortgageStatus;

      var


Скачать книгу