Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1: Introduction to SAS  SAS programs: A sequence of statements in a particular order  Rules for SAS statements: –Every SAS statement ends in.

Similar presentations


Presentation on theme: "Chapter 1: Introduction to SAS  SAS programs: A sequence of statements in a particular order  Rules for SAS statements: –Every SAS statement ends in."— Presentation transcript:

1 Chapter 1: Introduction to SAS  SAS programs: A sequence of statements in a particular order  Rules for SAS statements: –Every SAS statement ends in a semicolon –Upper/lower case does not matter in SAS 1 © Fall 2011 John Grego and the University of South Carolina

2 Chapter 1: Introduction to SAS  Rules for SAS statements: –Statements can continue on next line –Statements can be on same line as other statements –Statements can start in any column 2 © Fall 2011 John Grego and the University of South Carolina

3 Chapter 1: Introduction to SAS  Rules for SAS comments:  Comment “boxes” are popular  Comments: Two possible styles  *….; or /*….*/ *Here is a comment; /* Here is another comment */ 3 © Fall 2011 John Grego and the University of South Carolina

4 SAS Data Sets  Specially formatted “worksheet”; current extension is.sas7bdat  Variables represented by Columns  Observations represented by Rows  Two Data Types; Numeric and Character  Default variable length is 8 4

5 SAS Data Sets  Choose data type based on how you use the variable  Example: SSN could be character  Missing data in SAS is denoted by a period (.) for numeric data and a null space for character data  Variable attributes (Type, Length, etc) are stored with the SAS data set 5

6 Rules for Naming SAS variables  Names can be 32 characters or fewer  Names must begin with a letter or underscore (_)  Names may contain only letters, number, and underscores  Names can contain upper/lower case letters 6

7 Two Parts to SAS Programs DATA step:  When ads ask for “SAS experience”, they mean experience with the DATA step  Begins with DATA statements  Reads in and modifies data  Creates SAS data set 7

8 Two Parts to SAS Programs PROC step:  Begins with PROC statements  Performs (statistical) analyses on data  Produces results/outputs 8

9 Two Parts to SAS Programs  Steps may contain many statements  Steps usually end when: 1.Another step begins 2.A RUN; statement appears DATA height;..SAS statements.. run; PROC PRINT DATA=height; run; PROC REG;..SAS statements.. run; 9

10 Two Parts to SAS Programs  SAS reads data sets one observation at a time-implicit looping  SAS executes steps line by line  Be sure to enter statements in correct order 10

11 Windowing Environment  PCs in labs and classrooms use windowing environment.  See Sec 1.5 for information on other SAS environments 11

12 SAS Windows  3 windows in one frame and 2 windows in another  “Editor”: Type in and edit SAS programs in the editor window (color-coded)  “Log”: Contains notes about SAS code execution, SAS data sets, and errors/warnings  “Output”: Printable results 12

13 SAS Windows  3 windows in one frame and 2 windows in another  “Results”: Table of contents for Output window  “Explorer”: Icons for file folders, SAS libraries, and SAS data sets  Additional output windows (HTML format, Graphics) 13

14 Windowing Environment  Once program is entered into “Editor”, save it, then choose “Submit” under “Run” menu (Or “make the little man run”)  Go to Output and Log windows for results or notes  If program disappears, choose “Recall Last Submit” under “Run” menu 14

15 Windowing Environment  In any window: Choose “Edit”->”Clear All” by right-clicking to clear window (Output and Log windows can get cluttered)  Log window -> Error messages, number of observations and variables created. Often hard to interpret, but into on intermediate datasets can be helpful 15

16 Windowing Environment Printing/Saving Output:  Directly from Output window (too many page breaks—wastes paper)  Using Results window (can print/save partial output—right click; select “Open in New Window”)  Copy to file (Word or Notepad); edit and print. 16

17 Windowing Environment Creating HTML Output:  Tools->Options/Preferences  Click “Create HTML”  Both styles of output will be available 17

18 SAS Libraries Location where SAS data sets and SAS files are stored Location where SAS data sets and SAS files are stored Often, an ordinary directory that contains non-SAS files as well Often, an ordinary directory that contains non-SAS files as well Built-in libraries: Sashelp, Sasuser, Work (default library) Built-in libraries: Sashelp, Sasuser, Work (default library) 18

19 SAS Libraries Creating Libraries:  In active Libraries windows, select File- >New, or right click and select New  Use method in Section 1.11, or select the sparkly file cabinet drawer Name:  Libref (8 characters or fewer)  Path (location for data sets to be stored)  Enable at start-up 19

20 SAS Libraries  Library location can easily be forgotten (if not enabled)  SAS prompts you to save in a separate file the code that created the library  It’s convenient to include simple code at the top of your file: libname mitchell ‘z:\stat 540\Mitchell’; 20

21 SAS Libraries Be careful that you do not write over a saved file: /* This code stores a data set from WORK in MITCHELL */ /* It can also accidentally overwrite any changes in mitchell.anpp in subsequent runs */ libname mitchell ‘z:\stat 540\mitchell’; data mitchell.ANPP; set ANPP; 21

22 Viewing Data Sets in Explorer  Double-click on a library, then double-click on an available data set (e.g, “Class” in Sashelp) or right-click and select Properties.  Close window when finished examining data set  Examine data set worksheet for problems  Right-click on column label and select “Column attributes” to obtain info on the variable in the data set. 22

23 SAS System Options  OPTIONS statement can appear before the DATA statement  Frequently used to improve pagination and on-screen readabililty of output  OPTIONS LINESIZE=80 NOCENTER NODATE PAGESIZE=64 NONUMBER; 23


Download ppt "Chapter 1: Introduction to SAS  SAS programs: A sequence of statements in a particular order  Rules for SAS statements: –Every SAS statement ends in."

Similar presentations


Ads by Google