Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1: Introduction to SAS

Similar presentations


Presentation on theme: "Chapter 1: Introduction to SAS"— 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 © Fall 2011 John Grego and the University of South Carolina

2 SAS Statements 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 © Fall 2011 John Grego and the University of South Carolina

3 SAS Comments Rules for SAS comments: Comment “boxes” are popular
Comments: Two possible styles *….; or /*….*/ *Here is a comment; /* Here is another comment */ /* could be a control symbol in older languages. © 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 32,767 variables or more Observations represented by Rows Two Data Types; Numeric and Character Default variable length is 8 Run agency.sas Go to WORK.agency and look at worksheet. Two data types, but many data formats (show in Column Attributes).

5 SAS Variables 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

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, numbers, and underscores Names can contain upper/lower case letters I keep variable names short.

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 Employers are interested in data management skills

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

9 Steps and Statements Steps may contain many statements
Steps usually end when: Another step begins A RUN; statement appears DATA height; ..SAS statements.. run; PROC PRINT DATA=height; PROC REG; Another step (DATA or PROC). There are several less common ways to end a step (quit, etc)

10 Implicit Looping 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 Order is fungible in SAS data steps (though text indicates otherwise).

11 Windowing Environment
PCs in labs and classrooms use windowing environment. See Sec for information on other SAS environments SAS OnDemand uses Studio, not Display Manager. Enterprise Guide has a project-based windowing environment.

12 SAS Windows: Right Frame
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 “Results Viewer”: Printable results Other named SAS programs also appear. Results Viewer has supplanted Output.

13 SAS Windows: Left Frame
3 windows in one frame and 2 windows in another “Results”: Table of contents for Results Viewer window “Explorer”: Icons for file folders, SAS libraries, and SAS data sets Additional output windows (Output, Graphics) I don’t use Results as much as I should. SPSSX has this output layout too. Run agency.sas (if you haven’t already).

14 Running Programs 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

15 Log Window 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 info on intermediate datasets can be helpful Open in New Window does not open individual objects…

16 Results Viewer Window Printing/Saving Output:
Directly from Results Viewer window (cut-and-paste to file (Word or Notepad); edit and print; Using Results window (format options are limited)

17 Output Window Creating Output window:
Tools->Options->Preferences->Results Click “Create Listing” Both styles of output will be available

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

19 Creating 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

20 SAS Library Locations 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’;

21 Over-writing a Permanent Data Set
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; Mitchell.anpp may be a base data set for many subsequent data steps, so this write-over is severe.

22 Viewing Data Sets in Explorer
Double-click on a library, then double-click on an available dat a 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.

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;


Download ppt "Chapter 1: Introduction to SAS"

Similar presentations


Ads by Google