Hechsp 001 Chapter 2

2,545 views

Published on

SAS for HS Chapter 2

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,545
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
76
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Hechsp 001 Chapter 2

    1. 1. Chapter 2 Getting Started with the SAS ® System
    2. 2. Section 2.1 Introduction to SAS Programs
    3. 3. <ul><ul><li>State the components of a SAS program. </li></ul></ul><ul><ul><li>State the modes in which you can run a SAS program. </li></ul></ul>Objectives
    4. 4. SAS Vocabulary <ul><ul><li>SAS program </li></ul></ul><ul><ul><li>DATA step </li></ul></ul><ul><ul><li>PROC step </li></ul></ul>
    5. 5. Turning Data into information DATA Step Data Output SAS Data Set PROC Step LastName FirstName Age TORRES JAN 23 LANGKAMM SARAH 46 SMITH MICHAEL 71 WAGSCHAL NADJA 37 TOERMOEN JOCHEN 16
    6. 6. SAS Programs <ul><li>A SAS program is a sequence of steps that the user submits for execution. </li></ul>DATA Step Output Raw Data SAS Data Set SAS Data Set 129986542,Fred,Barnes,54,654543681,Alicia,Burnett,23,241453384,Connor,Coats PROC Step LastName FirstName Age TORRES JAN 23 LANGKAMM SARAH 46 SMITH MICHAEL 71 WAGSCHAL NADJA 37 TOERMOEN JOCHEN 16 LastName FirstName Age TORRES JAN 23 LANGKAMM SARAH 46 SMITH MICHAEL 71 WAGSCHAL NADJA 37 TOERMOEN JOCHEN 16 DATA steps are typically used to create SAS data sets. PROC (procedure) steps are used to process SAS data sets (generate reports and sort data).
    7. 7. data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff; class JobTitle; var Salary; run; DATA Step PROC Steps SAS Programs
    8. 8. SAS Programs <ul><li>SAS executes one step at a time, statement by statement , independently of one another. </li></ul><ul><li>Other programming languages compile the entire program, and then execute the entire program at once. </li></ul>
    9. 9. Step Boundaries <ul><li>SAS steps begin with DATA statements or PROC statements. </li></ul><ul><li>SAS detects the end of a step when it encounters </li></ul><ul><ul><li>a RUN statement (for most steps) </li></ul></ul><ul><ul><li>a QUIT statement (for some run-group procedures) </li></ul></ul><ul><ul><li>the beginning of another step (DATA or PROC statement). </li></ul></ul>data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff; class JobTitle; var Salary; run; DATA Step PROC Steps
    10. 10. data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; proc means data=work.staff; class JobTitle; var Salary; run; Step Boundaries
    11. 11. Running a SAS Program <ul><li>Versions of SAS exist for several different operating systems. </li></ul><ul><li>Windows </li></ul><ul><ul><li>SAS Windowing Environment </li></ul></ul><ul><ul><li>SAS Enterprise Guide (point-and-click interface) </li></ul></ul><ul><li>UNIX </li></ul><ul><ul><li>SAS Windowing Environment only </li></ul></ul><ul><li>Mainframe </li></ul><ul><ul><li>SAS Windowing Environment only </li></ul></ul>
    12. 12. SAS Windowing Environment <ul><li>Interactive windows enable you to interface with SAS. </li></ul><ul><li>SAS Windowing Environment Interface </li></ul>
    13. 13. Section 2.2 Running SAS Programs
    14. 14. <ul><ul><li>Start SAS and include a SAS program in your session. </li></ul></ul><ul><ul><li>Submit a program and browse the results. </li></ul></ul><ul><ul><li>Navigate the SAS windowing environment. </li></ul></ul>Objectives
    15. 15. SAS Vocabulary KEYS LOG Program Editor SAS log Enhanced Editor SUBMIT WED Editor window OUTPUT INCLUDE CLEAR LOG SAS Output
    16. 16. Submitting a SAS Program When you execute a SAS program, the output generated by SAS is divided into two major parts: contains reports generated by SAS procedures and DATA steps. SAS output contains information about the processing of the SAS program, including any warning and error messages. SAS log
    17. 17. SAS Log 1 data work.staff; 2 infile 'raw-data-file'; 3 input LastName $ 1-20 FirstName $ 21-30 4 JobTitle $ 36-43 Salary 54-59; 5 run; NOTE: The infile 'raw-data-file' is: File Name= 'raw-data-file', RECFM=V,LRECL=256 NOTE: 18 records were read from the infile 'raw-data-file'. The minimum record length was 59. The maximum record length was 59. NOTE: The data set WORK.STAFF has 18 observations and 4 variables. 6 proc print data=work.staff; 7 run; NOTE: There were 18 observations read from the dataset WORK.STAFF. 8 proc means data=work.staff; 9 class JobTitle; 10 var Salary; 11 run; NOTE: There were 18 observations read from the dataset WORK.STAFF.
    18. 18. PRINT Procedure Output The SAS System First Obs LastName Name JobTitle Salary 1 TORRES JAN Pilot 50000 2 LANGKAMM SARAH Mechanic 80000 3 SMITH MICHAEL Mechanic 40000 4 LEISTNER COLIN Mechanic 36000 5 WADE KIRSTEN Pilot 85000 6 TOMAS HARALD Pilot 105000 7 WAUGH TIM Pilot 70000 8 LEHMANN DAGMAR Mechanic 64000 9 TRETTHAHN MICHAEL Pilot 100000 10 TIETZ OTTO Pilot 45000 11 O'DONOGHUE ART Mechanic 52000 12 WALKER THOMAS Pilot 95000 13 NOROVIITA JOACHIM Mechanic 78000 14 OESTERBERG ANJA Mechanic 80000 15 LAUFFER CRAIG Mechanic 40000 16 TORR JUGDISH Pilot 45000 17 WAGSCHAL NADJA Pilot 77500 18 TOERMOEN JOCHEN Pilot 65000
    19. 19. MEANS Procedure Output The SAS System The MEANS Procedure Analysis Variable : Salary N JobTitle Obs N Mean Std Dev Minimum ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ Mechanic 8 8 58750.00 19151.65 36000.00 Pilot 10 10 73750.00 22523.14 45000.00 ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ Analysis Variable : Salary N JobTitle Obs Maximum ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ Mechanic 8 80000.00 Pilot 10 105000.00 ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
    20. 20. <ul><li>This demonstration illustrates how to invoke SAS and open and run a SAS program. </li></ul>Running a SAS Program
    21. 21. <ul><li>There are two ways to open SAS: </li></ul><ul><li>Menu-driven </li></ul><ul><li>Select Start  Programs  SAS  SAS 9.1 . </li></ul><ul><li>Desktop shortcut </li></ul><ul><li>SAS toolbar button </li></ul>Demonstration – Invoking SAS
    22. 22. Command Box Output Window (behind) Current Working Directory Menus Toolbar Explorer Log Window Enhanced Editor
    23. 23. <ul><li>There are three ways to open a SAS program: </li></ul><ul><li>Command Box </li></ul><ul><li>Type the INCLUDE command in the Command Box. </li></ul><ul><li>Menu-driven </li></ul><ul><li>Select File  Open . </li></ul><ul><li>Toolbar Shortcut </li></ul><ul><li>Open button </li></ul>Demonstration – Running a SAS Program
    24. 24. <ul><li>Issue the INCLUDE command in the command box to open or include a program in your SAS session. </li></ul><ul><li>Type include and the name of the file containing the program in quotation marks. Then press ENTER. </li></ul><ul><li>The program is included in the Editor window. </li></ul>Demonstration – Running a SAS Program
    25. 25. <ul><li>You can use the SAS Enhanced Editor to do the following: </li></ul><ul><ul><li>access and edit existing SAS programs </li></ul></ul><ul><ul><li>write new SAS programs </li></ul></ul><ul><ul><li>submit SAS programs </li></ul></ul><ul><ul><li>save SAS programs </li></ul></ul>Demonstration – Running a SAS Program
    26. 26. <ul><li>In the SAS Enhanced Editor, the syntax in your SAS program is color-coded to distinguish between the following: </li></ul><ul><ul><li>step boundaries </li></ul></ul><ul><ul><li>SAS keywords </li></ul></ul><ul><ul><li>data set names </li></ul></ul><ul><ul><li>variable names </li></ul></ul>Demonstration – Running a SAS Program
    27. 27. <ul><li>There are three ways to submit a SAS program: </li></ul><ul><li>Menu-driven </li></ul><ul><li>Select File  Submit . </li></ul><ul><li>Command Box </li></ul><ul><li>Type the SUBMIT command in the Command Box. </li></ul><ul><li>Toolbar Shortcut </li></ul><ul><li>Submit button </li></ul>Demonstration – Running a SAS Program
    28. 28. <ul><li>If your code generates output, the output is displayed in the SAS Output window. </li></ul><ul><li>When the Output window moves to the front to become the active window, you should select and view the SAS log first. </li></ul>Demonstration – Running a SAS Program
    29. 29. <ul><li>Always check the SAS log when you submit a program. </li></ul><ul><li>Browse the messages that the program generated. </li></ul>Demonstration – Running a SAS Program Remember
    30. 30. <ul><li>There are three ways to view the SAS log: </li></ul><ul><li>Menu-driven </li></ul><ul><li>Select View  Log . </li></ul><ul><li>Command Box </li></ul><ul><li>Type the LOG command in the Command Box. </li></ul><ul><li>Tabs </li></ul><ul><li>Select the Log tab. </li></ul>Demonstration – Running a SAS Program
    31. 31. <ul><li>Examining Your Program Results </li></ul><ul><li>The Log window has the following characteristics: </li></ul><ul><ul><li>is one of the primary windows and is open by default </li></ul></ul><ul><ul><li>acts as an audit trail for your SAS session </li></ul></ul><ul><ul><li>has messages that are written to the log in the order in which they are generated </li></ul></ul><ul><li>As you continue to submit your programs, SAS writes messages to the bottom of the log. </li></ul>Demonstration – Running a SAS Program
    32. 32. <ul><li>Navigating in the Log </li></ul><ul><ul><li>Use the PAGE UP and PAGE DOWN keys. </li></ul></ul><ul><ul><li>Use the scroll bar. </li></ul></ul><ul><li>Make certain that you review the complete log entry for your submission. </li></ul><ul><li>Look in the log for the beginning of your current code submission. </li></ul>Demonstration – Running a SAS Program
    33. 33. <ul><li>The Log window contains the programming statements that are submitted, as well as notes about the following: </li></ul><ul><ul><li>any files that were read </li></ul></ul><ul><ul><li>the records that were read </li></ul></ul><ul><ul><li>the program execution and results </li></ul></ul>Demonstration – Running a SAS Program
    34. 34. <ul><li>By default, the following conventions appear: </li></ul><ul><ul><li>Notes are written in blue . </li></ul></ul><ul><ul><ul><li>Read these because they might be 'good' or 'bad‘, depending on the intention. </li></ul></ul></ul><ul><ul><li>Warnings are written in green . </li></ul></ul><ul><ul><ul><li>Read these because they might be 'good' or 'bad‘, depending on the intention. </li></ul></ul></ul><ul><ul><li>Errors are written in red . </li></ul></ul><ul><ul><ul><li>Read these carefully. </li></ul></ul></ul><ul><ul><ul><li>Errors stop SAS processing and indicate that something must be corrected. </li></ul></ul></ul>Demonstration – Running a SAS Program
    35. 35. <ul><li>You might want a clean log when you submit your program. </li></ul><ul><li>To clear the contents of the window, do one of the following: </li></ul><ul><ul><li>Issue the CLEAR LOG command in the command box. </li></ul></ul><ul><ul><li>Select Edit  Clear All . </li></ul></ul><ul><ul><li>Select the New icon. </li></ul></ul><ul><li> The icon resembles a clean sheet of paper, and you want a blank Log window. </li></ul>Demonstration – Running a SAS Program
    36. 36. <ul><li>There are three ways to view the Output window: </li></ul><ul><li>Menu-driven </li></ul><ul><li>Select View  Output . </li></ul><ul><li>Command Box </li></ul><ul><li>Type the OUTPUT command in the Command Box. </li></ul><ul><li>Select the Output tab. </li></ul>Demonstration – Running a SAS Program
    37. 37. <ul><li>Examining Your Program Results </li></ul><ul><li>The Output window </li></ul><ul><ul><li>is one of the primary windows and is open by default </li></ul></ul><ul><ul><li>becomes the active window each time that it receives output </li></ul></ul><ul><ul><li>automatically accumulates output in the order in which it is generated. </li></ul></ul><ul><li>SAS writes to the bottom of the window each time that output is generated. </li></ul>Demonstration – Running a SAS Program
    38. 38. <ul><li>You might want a clean Output window when you submit your program. </li></ul><ul><li>With the Output window active, you can do one of the following: </li></ul><ul><ul><li>Issue the CLEAR OUTPUT command in the command box. </li></ul></ul><ul><ul><li>Select Edit  Clear All to clear the contents of the window. </li></ul></ul><ul><ul><li>Click on the New button. </li></ul></ul>Demonstration – Running a SAS Program
    39. 39. <ul><li>Examining Your Program Results </li></ul><ul><li>The Output window displays the last page of output generated by the program submitted. </li></ul><ul><li>To scroll vertically in the Output window, use one of the following methods: </li></ul><ul><ul><li>the vertical scrollbar </li></ul></ul><ul><ul><li>the PAGE UP or PAGE DOWN keys on the keyboard </li></ul></ul><ul><ul><li>issue the TOP and BOTTOM commands </li></ul></ul>Demonstration – Running a SAS Program
    40. 40. <ul><li>To return to the Enhanced Editor window, use one of the following methods: </li></ul><ul><ul><li>Select the Editor tab. </li></ul></ul><ul><ul><li>If the window is visible, select it to make it active. </li></ul></ul>Demonstration – Running a SAS Program
    41. 41. What Do You Do If… <ul><li>What if you close a window accidentally? </li></ul><ul><ul><li>Select View and the window that you want to open (Log, Editor, Output). </li></ul></ul><ul><ul><li>If you close the Log or Output window, you need to reopen it in order to see results. </li></ul></ul><ul><ul><li>If you close the Editor window, you need to open the Enhanced Editor window. </li></ul></ul>
    42. 42. What Do You Do If… <ul><li>Why are there two different types of editors? </li></ul><ul><li>On the UNIX and Mainframe platforms, you can only use the Program Editor. </li></ul><ul><li>Windows supports the Program Editor (for backward compatibility) as well as the Enhanced Editor. </li></ul><ul><li>Submit the same program in each window and see what happens. </li></ul>
    43. 43. Program Editor versus Enhanced Editor Keeps code after a submit Code not kept after a submit Can have many windows open Can only have one window open Has a blue + added to the icons Title bar: Editor Title bar: Program Editor Coloring is different. Coloring is different. Enhanced Editor Program Editor
    44. 44. What Do You Do If… <ul><li>The code you forgot to save disappeared? </li></ul><ul><li>Do you have to retype it? </li></ul><ul><li>Is there way to get it back? </li></ul>
    45. 45. What Do You Do If… <ul><li>… you lost your previously submitted code? </li></ul><ul><li>Select Run  Recall Last Submit . </li></ul><ul><li>The code is returned to your Editor window. </li></ul>
    46. 46. <ul><li>This exercise reinforces the concepts discussed previously. </li></ul>Exercise
    47. 47. <ul><li>1. Submitting a Program </li></ul><ul><ul><li>With the Editor window active, open the SAS program c02ex1.sas </li></ul></ul><ul><ul><li>Submit the program. </li></ul></ul><ul><ul><ul><li>Based on the report in the Output window, how many observations and variables are in the data set? </li></ul></ul></ul><ul><ul><li>Examine the Log window. </li></ul></ul><ul><ul><ul><li>Based on the log notes, how many observations and variables are in the data set? </li></ul></ul></ul><ul><ul><li>Clear the Log and Output windows. </li></ul></ul>Exercises
    48. 48. <ul><li>2. Issuing the KEYS Command </li></ul><ul><ul><li>The Keys window is </li></ul></ul><ul><ul><ul><li>a secondary window </li></ul></ul></ul><ul><ul><ul><li>used to browse or change function key definitions. </li></ul></ul></ul><ul><ul><ul><li>closed by issuing the END command. </li></ul></ul></ul><ul><ul><ul><li>Issue the KEYS command. Browse the contents of the window by scrolling vertically. </li></ul></ul></ul><ul><ul><ul><li>Close the KEYS window. </li></ul></ul></ul>Exercises
    49. 49. <ul><li>You want to clear the Log and Output windows by simply pressing a button. </li></ul><ul><li>Using the KEYS command, you can set the F12 key to issue the commands. </li></ul>Exercises
    50. 50. <ul><li>3. Setting a Function Key </li></ul><ul><ul><li>Issue the KEYS command to access the Keys window. </li></ul></ul><ul><ul><li>Click in the definition area next to the F12 key. </li></ul></ul><ul><ul><li>Type the commands that you want to assign to the key, and separate them with a semicolon. Clear Log; Clear Output </li></ul></ul><ul><ul><li>Close the window. SAS automatically saves your definition in your user preferences in the Sasuser library. The key will be set every time that you log on to SAS. </li></ul></ul><ul><ul><li>Press the F12 key. What happens? </li></ul></ul>Exercises
    51. 51. <ul><li>Setting a Function Key </li></ul><ul><ul><li>Any of the commands that can be issued in the command box can be assigned to a function key. </li></ul></ul><ul><ul><li>Notice that SUBMIT is a command, and does not go in a program. </li></ul></ul><ul><ul><li>However, RUN is a statement that goes inside a program. You cannot use it in the command box, nor as a hot key. </li></ul></ul><ul><ul><li>Statements go in programs. </li></ul></ul><ul><ul><li>Commands go in the command box. </li></ul></ul>Exercises
    52. 52. Section 2.3 Mastering Fundamental Concepts
    53. 53. <ul><ul><li>Define the components of a SAS data set. </li></ul></ul><ul><ul><li>Define a SAS variable. </li></ul></ul><ul><ul><li>Identify a missing value and a SAS date value. </li></ul></ul><ul><ul><li>State the naming conventions for SAS data sets and variables. </li></ul></ul><ul><ul><li>Explain SAS syntax rules. </li></ul></ul><ul><ul><li>Investigate a SAS data set using the CONTENTS and PRINT procedures. </li></ul></ul>Objectives
    54. 54. SAS Vocabulary <ul><ul><li>SAS Data Set </li></ul></ul><ul><ul><li>Descriptor Portion </li></ul></ul><ul><ul><li>PROC CONTENTS </li></ul></ul><ul><ul><li>Data Portion </li></ul></ul><ul><ul><li>Character Variables </li></ul></ul><ul><ul><li>Numeric Variables </li></ul></ul><ul><ul><li>SAS Names </li></ul></ul><ul><ul><li>SAS Date Value </li></ul></ul><ul><ul><li>Character Missing Value </li></ul></ul><ul><ul><li>Numeric Missing Value </li></ul></ul><ul><ul><li>PROC PRINT </li></ul></ul><ul><ul><li>SAS Statement </li></ul></ul><ul><ul><li>Free Format </li></ul></ul><ul><ul><li>SAS Comments </li></ul></ul>
    55. 55. <ul><li>In this section, you will learn basic SAS concepts. </li></ul><ul><li>These concepts are the basics that you need to know so that you can program in SAS. </li></ul>Mastering Fundamental Concepts
    56. 56. SAS Data Set Terminology SAS documentation and text in the SAS windowing environment use the following terms interchangeably: SAS Data Set Table Variable Column Observation Row
    57. 57. SAS Data Sets <ul><li>A SAS data set consists of two parts. </li></ul>SAS Data Set Descriptor Portion Data Portion
    58. 58. SAS Data Sets <ul><li>A SAS data set is a specially structured file that contains data values. </li></ul><ul><li>Data must be in the form of a SAS data set to be processed by most SAS procedures. </li></ul>
    59. 59. <ul><li>SAS data sets have a descriptor portion and a data portion. </li></ul>SAS Data Sets General data set information * data set name * data set label * date/time created * storage information * number of observations Information for each variable * Name * Type * Length * Position * Format * Informat * Label Descriptor Portion Data Portion
    60. 60. <ul><li>The descriptor portion of a SAS data set simply describes the data. It contains the following: </li></ul><ul><ul><li>general information about the SAS data set such as data set name and number of observations </li></ul></ul><ul><ul><li>variable attributes such as name, type, length, position, informat, format, and label </li></ul></ul><ul><ul><ul><li>How can you see the descriptor portion of a SAS data set? </li></ul></ul></ul><ul><ul><ul><ul><li>Use the CONTENTS procedure. </li></ul></ul></ul></ul>Browsing the Descriptor Portion
    61. 61. <ul><li>General form of the CONTENTS procedure: </li></ul><ul><li>Example: </li></ul>Browsing the Descriptor Portion PROC CONTENTS DATA= SAS-data-set ; RUN; proc contents data=sashelp.class; run;
    62. 62. Partial PROC CONTENTS Output The SAS System The CONTENTS Procedure Data Set Name SASHELP.CLASS Observations 19 Member Type DATA Variables 5 Engine V9 Indexes 0 Created Wednesday, May 12, 2004 Observation Length 40 10:53:55 PM Last Modified Wednesday, May 12, 2004 Deleted Observations 0 10:53:55 PM Protection Compressed NO Data Set Type Sorted NO Alphabetic List of Variables and Attributes # Variable Type Len 3 Age Num 8 4 Height Num 8 1 Name Char 8 2 Sex Char 1 5 Weight Num 8
    63. 63. SAS Data Sets: Data Portion Numeric values Variable names Variable values LastName FirstName JobTitle Salary TORRES JAN Pilot 50000 LANGKAMM SARAH Mechanic 80000 SMITH MICHAEL Mechanic 40000 WAGSCHAL NADJA Pilot 77500 TOERMOEN JOCHEN Pilot 65000 The data portion of a SAS data set is a rectangular table of character and/or numeric data values. Variable names are part of the descriptor portion, not the data portion. Character values
    64. 64. <ul><li>There are two types of variables: character and numeric. </li></ul><ul><li>Character variables </li></ul><ul><ul><li>contain any value: letters, numbers, special characters, and blanks </li></ul></ul><ul><ul><li>are stored with a length of 1 to 32,767 bytes </li></ul></ul><ul><ul><li>have one byte equal to one character </li></ul></ul><ul><ul><li>are left-aligned. </li></ul></ul>SAS Variable Values continued...
    65. 65. SAS Variable Values <ul><li>Numeric variables </li></ul><ul><ul><li>are stored as floating point numbers in 8 bytes of storage by default, allowing for 16 to 17 significant digits </li></ul></ul><ul><ul><li>are not restricted to 8 digits </li></ul></ul><ul><ul><li>are right-aligned. </li></ul></ul>
    66. 66. <ul><li>SAS data set and variable names must adhere to the following rules: </li></ul><ul><ul><li>can be up to 32 characters long. </li></ul></ul><ul><ul><li>can be uppercase, lowercase, or mixed-case. </li></ul></ul><ul><ul><li>must start with a letter or underscore. Subsequent characters can be numbers, letters, or underscores. </li></ul></ul>SAS Data Set and Variable Names
    67. 67. <ul><li>Select the valid default SAS names. </li></ul>Valid SAS Names  data5mon  data5mon  5monthsdata  five months data  data#5  fivemonthsdata  FiveMonthsData ...
    68. 68. <ul><li>Select the valid default SAS names. </li></ul>Valid SAS Names  data5mon  data5mon ...
    69. 69. <ul><li>Select the valid default SAS names. </li></ul>Valid SAS Names  data5mon ...
    70. 70. <ul><li>Select the valid default SAS names. </li></ul>Valid SAS Names  data5mon  data5mon  5monthsdata ...
    71. 71. <ul><li>Select the valid default SAS names. </li></ul>Valid SAS Names  data5mon  data5mon  5monthsdata ...
    72. 72. <ul><li>Select the valid default SAS names. </li></ul>Valid SAS Names  data5mon  data5mon  5monthsdata  data#5 ...
    73. 73. <ul><li>Select the valid default SAS names. </li></ul>Valid SAS Names  data5mon  data5mon  5monthsdata  data#5 ...
    74. 74. <ul><li>Select the valid default SAS names. </li></ul>Valid SAS Names  data5mon  data5mon  5monthsdata  data#5  five months data ...
    75. 75. <ul><li>Select the valid default SAS names. </li></ul>Valid SAS Names  data5mon  data5mon  5monthsdata  data#5  five months data ...
    76. 76. <ul><li>Select the valid default SAS names. </li></ul>Valid SAS Names  data5mon  data5mon  5monthsdata  five months data  data#5  fivemonthsdata ...
    77. 77. <ul><li>Select the valid default SAS names. </li></ul>Valid SAS Names  data5mon  data5mon  5monthsdata  five months data  data#5  fivemonthsdata ...
    78. 78. <ul><li>Select the valid default SAS names. </li></ul>Valid SAS Names  data5mon  data5mon  5monthsdata  five months data  data#5  fivemonthsdata  FiveMonthsData ...
    79. 79. <ul><li>Select the valid default SAS names. </li></ul>Valid SAS Names  data5mon  data5mon  5monthsdata  five months data  data#5  fivemonthsdata  FiveMonthsData
    80. 80. <ul><li>This exercise reinforces the concepts discussed previously. </li></ul>Exercise
    81. 81. <ul><li>Create your own SAS name. </li></ul><ul><li>Create a data set name for containing the names and birth dates of your family members for three generations. </li></ul><ul><li>Create a variable name for the column containing the name of the generation to which an individual belonged. </li></ul>Exercises
    82. 82. <ul><li>An important concept with data is dates. </li></ul><ul><li>You might need to do calculations on dates. </li></ul><ul><li>How old is a person or how much time passed between two dates? </li></ul>Dates in SAS
    83. 83. <ul><li>You have two character dates: </li></ul><ul><ul><ul><ul><li>01Jan2006 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>01Apr2006 </li></ul></ul></ul></ul><ul><li>If you sorted these dates, they would not display in chronological order, but in alphabetic order. </li></ul><ul><ul><ul><ul><li>01Apr2006 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>01Jan2006 </li></ul></ul></ul></ul><ul><li>Dates stored as numbers enable calculations and proper sorting. </li></ul>SAS Dates
    84. 84. <ul><li>SAS stores date values as numeric values. </li></ul><ul><li>A SAS date value is stored as the number of days between January 1, 1960, and a specific date. </li></ul>SAS Date Values 01JAN1959 01JAN1960 01JAN1961 store -365 0 366 display 01/01/1959 01/01/1960 01/01/1961
    85. 85. Missing Data Values LastName FirstName JobTitle Salary TORRES JAN Pilot 50000 LANGKAMM SARAH Mechanic 80000 SMITH MICHAEL Mechanic . WAGSCHAL NADJA Pilot 77500 TOERMOEN JOCHEN 65000 A value must exist for every variable for each observation. Missing values are valid values. A numeric missing value is displayed as a period . A character missing value is displayed as a blank .
    86. 86. Browsing the Data Portion <ul><li>The PRINT procedure displays the data portion of a SAS data set. </li></ul><ul><li>By default, PROC PRINT displays the following: </li></ul><ul><ul><li>all observations </li></ul></ul><ul><ul><li>all variables </li></ul></ul><ul><ul><li>an OBS column on the left side </li></ul></ul>
    87. 87. <ul><li>General form of the PRINT procedure: </li></ul><ul><li>Example: </li></ul>Browsing the Data Portion PROC PRINT DATA= SAS-data-set ; RUN; proc print data=work.staff; run; PROC is the keyword . PRINT is the procedure name .
    88. 88. PROC PRINT Output The SAS System First Obs LastName Name JobTitle Salary 1 TORRES JAN Pilot 50000 2 LANGKAMM SARAH Mechanic 80000 3 SMITH MICHAEL Mechanic 40000 4 LEISTNER COLIN Mechanic 36000 5 WADE KIRSTEN Pilot 85000 6 TOMAS HARALD Pilot 105000 7 WAUGH TIM Pilot 70000 8 LEHMANN DAGMAR Mechanic 64000 9 TRETTHAHN MICHAEL Pilot 100000 10 TIETZ OTTO Pilot 45000 11 O'DONOGHUE ART Mechanic 52000 12 WALKER THOMAS Pilot 95000 13 NOROVIITA JOACHIM Mechanic 78000 14 OESTERBERG ANJA Mechanic 80000 15 LAUFFER CRAIG Mechanic 40000 16 TORR JUGDISH Pilot 45000 17 WAGSCHAL NADJA Pilot 77500 18 TOERMOEN JOCHEN Pilot 65000
    89. 89. <ul><li>SAS statements </li></ul><ul><ul><li>usually begin with an identifying keyword </li></ul></ul><ul><ul><li>always end with a semicolon . </li></ul></ul>data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run ; proc print data=work.staff; run ; proc means data=work.staff; class JobTitle; var Salary; run ; SAS Syntax Rules continued...
    90. 90. SAS Syntax Rules <ul><ul><li>SAS statements are free-format. </li></ul></ul><ul><ul><ul><li>One or more blanks or special characters can be used to separate words </li></ul></ul></ul><ul><ul><ul><li>They can begin and end in any column </li></ul></ul></ul><ul><ul><ul><li>A single statement can span multiple lines </li></ul></ul></ul><ul><ul><ul><li>Several statements can be on the same line </li></ul></ul></ul><ul><li>Unconventional Spacing Example </li></ul>data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc means data=work.staff; class JobTitle; var Salary;run;
    91. 91. <ul><ul><li>SAS statements are free-format. </li></ul></ul><ul><ul><ul><li>One or more blanks or special characters can be used to separate words </li></ul></ul></ul><ul><ul><ul><li>They can begin and end in any column </li></ul></ul></ul><ul><ul><ul><li>A single statement can span multiple lines </li></ul></ul></ul><ul><ul><ul><li>Several statements can be on the same line </li></ul></ul></ul><ul><li>Unconventional Spacing Example </li></ul>SAS Syntax Rules data work . staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc means data=work.staff; class JobTitle; var Salary;run;
    92. 92. SAS Syntax Rules <ul><ul><li>SAS statements are free-format. </li></ul></ul><ul><ul><ul><li>One or more blanks or special characters can be used to separate words. </li></ul></ul></ul><ul><ul><ul><li>They can begin and end in any column. </li></ul></ul></ul><ul><ul><ul><li>A single statement can span multiple lines. </li></ul></ul></ul><ul><ul><ul><li>Several statements can be on the same line. </li></ul></ul></ul><ul><li>Unconventional Spacing Example </li></ul>data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc means data=work.staff; class JobTitle ; var Salary;run;
    93. 93. SAS Syntax Rules <ul><ul><li>SAS statements are free-format. </li></ul></ul><ul><ul><ul><li>One or more blanks or special characters can be used to separate words. </li></ul></ul></ul><ul><ul><ul><li>They can begin and end in any column. </li></ul></ul></ul><ul><ul><ul><li>A single statement can span multiple lines. </li></ul></ul></ul><ul><ul><ul><li>Several statements can be on the same line. </li></ul></ul></ul><ul><li>Unconventional Spacing Example </li></ul>data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc means data=work.staff; class JobTitle; var Salary;run;
    94. 94. SAS Syntax Rules <ul><ul><li>SAS statements are free-format . </li></ul></ul><ul><ul><ul><li>One or more blanks or special characters can be used to separate words. </li></ul></ul></ul><ul><ul><ul><li>They can begin and end in any column. </li></ul></ul></ul><ul><ul><ul><li>A single statement can span multiple lines. </li></ul></ul></ul><ul><ul><ul><li>Several statements can be on the same line. </li></ul></ul></ul><ul><li>Unconventional Spacing Example </li></ul>data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc means data=work.staff; class JobTitle; var Salary;run; ...
    95. 95. <ul><li>Indentation and good spacing makes the program easier to read. </li></ul><ul><li>Conventional Spacing Example </li></ul>data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff; class JobTitle; var Salary; run; SAS Syntax Rules
    96. 96. <ul><li>You can comment a block of text or code. </li></ul><ul><ul><li>Type /* to begin a comment. </li></ul></ul><ul><ul><li>Type your comment text. </li></ul></ul><ul><ul><li>Type */ to end the comment. </li></ul></ul>/* Create work.staff data set */ data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; /* Produce listing report of work.staff */ proc print data=work.staff; run; SAS Comments
    97. 97. <ul><li>Commenting one statement. </li></ul><ul><ul><li>Type an asterisk (*) at the beginning of the statement. </li></ul></ul><ul><ul><li>Everything that is between the asterisk and the semicolon is a comment. </li></ul></ul><ul><li> The * comments the entire statement, not only one line. How does SAS recognize the end of a statement? </li></ul>SAS Comments data work.staff; infile ' raw-data-file '; *input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run;
    98. 98. Shortcut to Comments <ul><ul><li>Highlight what you want to comment. </li></ul></ul><ul><ul><li>Hold down the CTRL and / buttons. </li></ul></ul><ul><ul><li>To Undo: Highlight and hold down the CTRL, SHIFT, and / buttons. </li></ul></ul>
    99. 99. <ul><li>This exercise reinforces the concepts discussed previously. </li></ul>Exercise – Section 2.3
    100. 100. Section 2.4 Diagnosing and Correcting Syntax Errors
    101. 101. <ul><ul><li>Identify SAS syntax errors. </li></ul></ul><ul><ul><li>Debug and edit a program with errors. </li></ul></ul><ul><ul><li>Resubmit the corrected program. </li></ul></ul><ul><ul><li>Save the corrected program. </li></ul></ul>Objectives
    102. 102. SAS Vocabulary <ul><ul><li>Syntax Errors </li></ul></ul><ul><ul><li>Options </li></ul></ul><ul><ul><li>RECALL </li></ul></ul>
    103. 103. Syntax Errors <ul><li>Syntax errors include the following: </li></ul><ul><ul><li>misspelled keywords </li></ul></ul><ul><ul><li>missing or invalid punctuation </li></ul></ul><ul><ul><li>invalid options </li></ul></ul>daat work.staff; infile ‘emplist.dat’; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff run; proc means data=work.staff average max; class JobTitle; var Salary; run; Average is not a valid option.
    104. 104. Syntax Errors <ul><li>Procedure Options </li></ul><ul><ul><li>Options tell SAS that you want the procedure to be processed differently than its default behavior. </li></ul></ul><ul><ul><li>In this example, you want only two statistics displayed: average and max. </li></ul></ul><ul><ul><li>Average is not a valid option for PROC MEANS. </li></ul></ul>proc means data=work.staff average max; class JobTitle; var Salary; run;
    105. 105. Syntax Errors <ul><li>When SAS encounters a syntax error, SAS underlines where SAS thinks things went wrong. </li></ul><ul><li>The following information is written to the SAS log: </li></ul><ul><ul><li>the word ERROR or WARNING </li></ul></ul><ul><ul><li>the location of the error </li></ul></ul><ul><ul><li>an explanation of the error </li></ul></ul>
    106. 106. <ul><li>This demonstration illustrates these tasks: </li></ul><ul><ul><li>how to submit a SAS program that contains errors </li></ul></ul><ul><ul><li>diagnosing the errors </li></ul></ul><ul><ul><li>correcti n g the errors </li></ul></ul><ul><ul><li>savi n g the corrected program </li></ul></ul>Demonstration – Debugging a SAS Program
    107. 107. In this demonstration, you open a program that has errors and submit it. Find the errors and correct them. Programs to open: c02s4d1.sas c02s4d2.sas Demonstration – Debugging a SAS Program
    108. 108. <ul><li>Start with the program: </li></ul><ul><li>c02s4d1.sas </li></ul>Demonstration – Debugging a SAS Program
    109. 109. Submit a SAS Program with Errors daat work.staff; infile 'emplist.dat' ; input LastName $ 1 - 20 FirstName $ 21 - 30 JobTitle $ 36 - 43 Salary 54 - 59 ; run ; proc print data =work.staff run; proc means data =work.staff average max ; class JobTitle; var Salary; run ; Demonstration – Debugging a SAS Program
    110. 110. The SAS log contains error messages and warnings. 1 daat work.staff; ---- 14 WARNING 14-169: Assuming the symbol DATA was misspelled as daat.   2 infile ‘… emplist.dat '; 3 input LastName $ 1-20 FirstName $ 21-30 4 JobTitle $ 36-43 Salary 54-59; 5 run;   NOTE: The infile ‘… emplist.dat ' is: File Name=‘… emplist.dat ', RECFM=V,LRECL=256   NOTE: 18 records were read from the infile ‘… emplist.dat '. The minimum record length was 59. The maximum record length was 59. NOTE: The data set WORK.STAFF has 18 observations and 4 variables. Part 1 of 4 Demonstration – Debugging a SAS Program
    111. 111. The SAS log contains error messages and warnings. 6 7 proc print data=work.staff 8 run; --- 22 - 200 ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATA, DOUBLE, HEADING, LABEL, N, NOOBS, OBS, ROUND, ROWS, SPLIT, STYLE, UNIFORM, WIDTH. ERROR 200-322: The symbol is not recognized and will be ignored. 9   NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE PRINT used (Total process time): real time 0.06 seconds cpu time 0.06 seconds Part 2 of 4 Demonstration – Debugging a SAS Program
    112. 112. The SAS log contains error messages and warnings. 10 proc means data=work.staff average max; ------- --- 22 202 ERROR 22-322: Syntax error , expecting one of the following: ;, (, ALPHA, CHARTYPE, CLASSDATA, CLM, COMPLETETYPES, CSS, CV, DATA, DESCEND, DESCENDING, DESCENDTYPES, EXCLNPWGT, EXCLNPWGTS, EXCLUSIVE, FW, IDMIN, KURTOSIS, LCLM, MAX, MAXDEC, MEAN , MEDIAN, MIN, MISSING, N, NDEC, NMISS, NONOBS, NOPRINT, NOTHREADS, NOTRAP, NWAY, ORDER, P1, P10, P25, P5, P50, P75, P90, P95, P99, PCTLDEF, PRINT, PRINTALL, PRINTALLTYPES, PRINTIDS, PRINTIDVARS, PROBT, Q1, Q3, QMARKERS, QMETHOD, QNTLDEF, QRANGE, RANGE, SKEWNESS, STDDEV, STDERR, SUM, SUMSIZE, SUMWGT, T, THREADS, UCLM, USS, VAR, VARDEF. ERROR 202-322: The option or parameter is not recognized and will be ignored. 11 class JobTitle; 12 var Salary; 13 run; Part 3 of 4 Demonstration – Debugging a SAS Program
    113. 113. The SAS log contains error messages and warnings.   NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE MEANS used (Total process time): real time 0.05 seconds cpu time 0.05 seconds Part 4 of 4 Demonstration – Debugging a SAS Program
    114. 114. <ul><li>The log indicates that SAS </li></ul><ul><ul><li>assumed that the keyword DATA was misspelled and executed the DATA step </li></ul></ul><ul><ul><li>interpreted the word RUN as an option in the PROC PRINT statement (because there was a missing semicolon), so PROC PRINT was not executed </li></ul></ul><ul><ul><li>did not recognize the word AVERAGE as a valid option in the PROC MEANS statement, so the PROC MEANS step was not executed. </li></ul></ul>Demonstration – Debugging a SAS Program
    115. 115. <ul><li>If you use the Enhanced Editor, the program remains in the Editor window. </li></ul><ul><ul><li>However, if you use the Editor window, the code disappears with each submit. </li></ul></ul><ul><ul><li>Use the RECALL command or select Run  Recall Last Submit to recall the program that you submitted back to the Editor window. The original program is moved into the Editor window. </li></ul></ul>continued... Demonstration – Debugging a SAS Program
    116. 116. <ul><li>Edit the program. </li></ul><ul><ul><li>Correct the spelling of DATA. </li></ul></ul><ul><ul><li>Put a semicolon at the end of the PROC PRINT statement. </li></ul></ul><ul><ul><li>Change the word AVERAGE to MEAN in the PROC MEANS statement. </li></ul></ul><ul><li>Submit the program. </li></ul><ul><li>The program runs successfully without errors and generates output. </li></ul>continued... Demonstration – Debugging a SAS Program
    117. 117. data work.staff; infile 'emplist.dat' ; input LastName $ 1 - 20 FirstName $ 21 - 30 JobTitle $ 36 - 43 Salary 54 - 59 ; run ; proc print data =work.staff; run ; proc means data =work.staff mean max ; class JobTitle; var Salary; run ; Demonstration – Debugging a SAS Program
    118. 118. <ul><li>You do not always have to submit the entire program. You can submit part of a program. For example, perhaps you only want to submit the PROC PRINT step. </li></ul><ul><ul><li>Highlight the part of your program that you want to run. </li></ul></ul><ul><ul><li>Submit the program by selecting Run  Submit or clicking on the Submit button. </li></ul></ul><ul><li>Only the highlighted code is executed. </li></ul>Demonstration – Submitting Part of the Code
    119. 119. <ul><li>What happens if you do not highlight the entire step? </li></ul><ul><li>Submit only the PROC PRINT statement. </li></ul><ul><li>What happens? </li></ul><ul><ul><li>The Output window becomes active. </li></ul></ul><ul><ul><li>The log has no notes. </li></ul></ul><ul><ul><li>The PROC PRINT running message is displayed in the Editor window title bar (blue bar). </li></ul></ul>Demonstration – Submitting Part of the Code
    120. 120. <ul><li>Why is SAS telling you that PROC PRINT is still running? </li></ul><ul><ul><li>Did you get output in the Output window? </li></ul></ul><ul><ul><li>Are there any messages in the Log? </li></ul></ul>Demonstration – Submitting Part of the Code
    121. 121. <ul><li>How does SAS determine the end of the step? </li></ul><ul><li>Was the end of the step submitted to SAS? </li></ul><ul><li>No, SAS is still waiting. After SAS gets a step boundary, SAS can finish executing the step. </li></ul>Demonstration – Solution
    122. 122. <ul><li>Highlight the RUN statement and submit only that statement. </li></ul><ul><li>This enables you to see the output once. If you submit the entire procedure, you see the output twice. </li></ul>Demonstration – Solution
    123. 123. <ul><li>Open the second program: </li></ul><ul><li>c02s4d2.sas </li></ul>Demonstration – Debugging a SAS Program
    124. 124. Another Example <ul><li>Do you notice anything odd with this program? </li></ul>data work.staff; infile 'emplist.dat; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff mean max; class JobTitle; var Salary; run;
    125. 125. Using Quotation Marks in SAS <ul><li>Rules for using quotation marks are as follows: </li></ul><ul><ul><li>You can use single or double quotation marks. </li></ul></ul><ul><ul><li>Quotation marks must be in pairs. &quot; &quot; or ' ' </li></ul></ul><ul><ul><li>Quotation marks must match. </li></ul></ul><ul><ul><li>&quot; ' </li></ul></ul><ul><ul><li>Typically, it does not matter if you use double or single quotation marks, as long as they match. </li></ul></ul>=
    126. 126. Unbalanced Quot ation Marks <ul><li>The closing quot ation marks for the INFILE statement is missing . </li></ul>data work.staff; infile 'c:sasdataemplist.dat; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff run; proc means data=work.staff average max; class JobTitle; var Salary; run;
    127. 127. Unbalanced Quot ation Marks <ul><li>Submit the program and browse the SAS log. </li></ul><ul><li>There are no notes in the SAS log because all of the SAS statements after the INFILE statement became part of the quoted string. </li></ul><ul><li>The banner on the window indicates that the DATA step is still running because the RUN statement was not recognized. </li></ul>
    128. 128. Fixing Quotation Errors <ul><li>Simply adding the needed quotation mark and submitting the code will not work. </li></ul><ul><li>Why? </li></ul><ul><li>' The first two quotation marks are considered a matched pair. </li></ul><ul><li>' ' By adding the new quotation mark, you still have an unmatched quotation mark. </li></ul><ul><li>SAS continues to look for a match. </li></ul>
    129. 129. Fixing Quotation Errors <ul><li>Because you know that the problem is unmatched quotation marks, you want SAS to stop processing so that y o u can fix the error. </li></ul><ul><li>How? </li></ul><ul><li>There are two ways to fix the quotation marks: </li></ul><ul><li>1. Programmatically </li></ul><ul><li>2. Point and click </li></ul>
    130. 130. Programmatically <ul><li>You want SAS to stop processing because the code did not execute properly. </li></ul><ul><li>You will add some code to stop the SAS process and then delete that code. </li></ul>
    131. 131. Programmatically <ul><li>What is SAS waiting for? </li></ul><ul><li>SAS expects a single quotation mark followed by a semicolon. </li></ul><ul><li>You need to end the step with the RUN statement. </li></ul><ul><ul><li>'; run; </li></ul></ul>
    132. 132. Programmatically <ul><li>'; run; </li></ul><ul><li>What if you forgot to submit a RUN statement? You added an unbalanced quotation mark. </li></ul><ul><li>Make the first part a comment. </li></ul><ul><li>*' ; run; </li></ul>
    133. 133. Programmatically <ul><li>*&quot;; run; </li></ul><ul><li>What if you used a double quotation mark instead of single quotation mark in the program? </li></ul><ul><li>Does this solve the problem? </li></ul>
    134. 134. Programmatically <ul><li>*'; run ; </li></ul><ul><li>What if you used a double quotation mark instead of single quotation mark in the program? Does this solve that? </li></ul><ul><li>No , you need to account for both single and double quotation marks. </li></ul><ul><li>*'; *&quot;; run; </li></ul>
    135. 135. Programmatically <ul><li>Submit the following: </li></ul><ul><li> *'; *&quot;; run; </li></ul><ul><ul><li>If the quotation mark counter within SAS has an uneven number of quotation marks, SAS reads the quotation in the comment above as the matching quotation mark. </li></ul></ul><ul><ul><li>SAS then has an even number of quotation marks in the quotation mark counter and runs successfully, assuming no other errors occur. </li></ul></ul><ul><ul><li>Either double or single quotation marks can be used. </li></ul></ul>
    136. 136. <ul><li>To correct the problem, click the Break icon or press the CTRL and BREAK keys. </li></ul><ul><li>2. Select Cancel Submitted Statements in the Tasking Manager window and select OK . </li></ul>Point-and-Click
    137. 137. Point-and-Click <ul><li>Select Y to cancel submitted statements  OK . </li></ul>
    138. 138. Fixing the Program <ul><li>Select the Editor window to make it active. </li></ul><ul><li>Add a closing quot ation mark to the file reference in the INFILE statement. </li></ul><ul><li>Resubmit the program. </li></ul>
    139. 139. Resubmitting the Program 27 data work.staff; 28 infile 'raw-data-file' ; 29 input LastName $ 1-20 FirstName $ 21-30 30 JobTitle $ 36-43 Salary 54-59; 31 run;   NOTE: 18 records were read from the infile 'raw-data-file'. The minimum record length was 59. The maximum record length was 59. NOTE: The data set WORK.STAFF has 18 observations and 4 variables. 32 33 proc print data=work.staff; 34 run;   NOTE: There were 18 observations read from the dataset WORK.STAFF. 35 36 proc means data=work.staff mean max; 37 class JobTitle; 38 var Salary; 39 run; NOTE: There were 18 observations read from the dataset WORK.STAFF.
    140. 140. Saving a SAS Program <ul><li>There are two methods to save a SAS program: </li></ul><ul><li>Menu-driven Select File  Save . Select File  Save As . </li></ul><ul><li>Toolbar Shortcut </li></ul><ul><li>Save button </li></ul><ul><li> If changes were made to the program since it was last saved, SAS will put an asterisk * on the blue title bar of the Editor window. This indicates that you need to save the program. </li></ul>
    141. 141. What Happens If … <ul><li>… you forgot to save a program and need to get the code back? </li></ul><ul><li>If you did not close the SAS session, you can recall your code. </li></ul><ul><li>When you submit your code, SAS puts the text into a buffer. Code is added to this buffer every time that you submit. </li></ul>
    142. 142. What If You Need to Get the Code Back? <ul><li>This buffer is similar to a stack of plates in the cafeteria. </li></ul><ul><ul><li>When you submit your code, SAS puts the text into a buffer. </li></ul></ul><ul><ul><li>Code is added to this buffer every time that you submit code. </li></ul></ul><ul><ul><li>The last code block that is added to the buffer is the first code block available to remove (as with that stack of plates). </li></ul></ul>LIFO L ast I n F irst O ut
    143. 143. What If You Need to Get the Code Back? <ul><li>Use one of these methods: </li></ul><ul><ul><li>Select Run  Recall Last Submit . </li></ul></ul><ul><ul><li>Submit the RECALL command. </li></ul></ul><ul><li>Repeat this until you see the desired code in your Editor window. </li></ul><ul><li>SAS puts the new entries at the top of the editor window. </li></ul>Remember
    144. 144. <ul><li>Program statements accumulate in a recall buffer each time that you issue a SUBMIT command. </li></ul>Recall a Submitted Program daat work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff run; proc means data=work.staff average max; class JobTitle; var Salary; run; data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff mean max; class Jobtitle; var Salary; run; Submit Number 1 Submit Number 2
    145. 145. <ul><li>Issue the RECALL command (from the Run menu) once to recall the most recently submitted program. </li></ul>Recall a Submitted Program Submit Number 1 Submit Number 2 Issue RECALL once. Submit Number 2 statements are recalled. data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff mean max; class JobTitle; var Salary; run;
    146. 146. <ul><li>Issue the RECALL command again to recall Submit Number 1 statements. </li></ul>Recall a Submitted Program Submit Number 1 Submit Number 2 Issue RECALL again. daat work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff run; proc means data=work.staff average max; class JobTitle; var Salary; run; data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff mean max; class JobTitle; var Salary; run;
    147. 147. <ul><li>This exercise reinforces the concepts discussed previously. </li></ul>Exercise – Section 2.4

    ×