Introduction To The SAS System - California State University, Bakersfield

Transcription

Introduction to the SAS SystemMath 3210Dr. ZengDepartment of MathematicsCalifornia State University, Bakersfield

Outline Overview of SAS ProductsOverview of Base SAS SoftwareDATA step and PROC stepSAS Enterprise Guide EnvironmentSAS Studio EnvironmentRunning SAS and a sample sessionUsing SAS System Options

Overview of SAS Products Base SAS – data management and basicprocedures SAS/STAT – statistical analysis SAS/GRAPH – presentation quality graphics SAS/OR – Operations research SAS/ETS- Econometrics and Time Series Analysis SAS/IML – interactive matrix language SAS/Qc – quality control

Overview of Base SAS SoftwareBase SAS Software contains the following: A data management facility A programming language Data analysis and reporting utilities-Learning to use Base SAS enables you to work withthese features of SAS. It also prepares you to learnother SAS products which follow the same basic rules.

Data Management FacilitySAS organizes data into a rectangular form ortable that is called a SAS data set.

Programming LanguageRules for SAS StatementTo build a SAS data set with Base SAS, we need to write a program thatuses statements in the SAS programming language. Here are a fewrules for writing SAS statements: SAS statements end with a semicolon. You can enter SAS statements in lowercase, uppercase, or a mixtureof the two. You can begin SAS statements in any column of a line and writeseveral statements on the same line. You can begin a statement on one line and continue it on anotherline, but you cannot split a word between two lines. Words in SAS statements are separated by blanks or by specialcharacters

Rules for Most SAS NamesSAS names are used for SAS data set names, variablenames, and other items. The following rules apply: A SAS name can contain from one to 32 characters The first character must be a letter or an underscore ( ) Subsequent characters must be letters, numbers, orunderscores Blank spaces cannot appear in SAS names

DATA step and PROC step SAS program are constructed from two basic building blocks:DATA steps and PROC steps. Typically, a SAS program starts with a DATA step to create aSAS data set and then passes the data to a PROC step forprocessing. A step ends when SAS encounters a new step (marked by aDATA or PROC statement), a RUN, QUIT, STOP, or ABORTstatement.

Example: DATA StepThis is an example of SAS DATA step which is normallyused to produce SAS data sets.

Questions: In this SAS program, how many statements do you see?

Data Analysis and Reporting UtilitiesYou can program any number of analyses and reportswith SAS. It can also simplify programming for you withits library of built-in programs known as SASprocedures.A portion of a SAS program that begins with a PROC(procedure) statement and ends with a run statement(or it ended by another proc or data statement) iscalled a PROC step.

Example: PROC Step This procedure, known as the PRINT procedure, displays the variables in asimple, organized form. A PROC statement, which includes the word PROC, the name of theprocedure that you want to use, and the name of the SAS data set thatcontains the values (otherwise, SAS will use the most recently createddata set) a RUN statement, which indicates that the preceding group of statementsis ready to be executed.

Interface: SAS Enterprise Guide

Running your SAS programStep 1: Getting your program into the editor: The first thingyou need to do is get your program into the editor window.You can either type your program into the editor, or you canbring the program into the Editor window from a file. Forexample, you can select File- Open from the menu bar. Youcan also save the program to your computer.Step 2: Submitting your program: click the Run button.

Step 3: Viewing the SAS log: every time you submit aSAS program, SAS writes messages in your log. You areencouraged to check the log window regularly. If therewere error messages, they would appear in the log,indicating where SAS got confused and what action ittook.Step 4: Viewing your results :

Check out this video for more information aboutSAS Enterprise -enterprise-guide?autoStart true

SAS Studio InterfaceSAS Studio is a browser based program whichhas almost the same functions as SAS EnterpriseGuide. Check out this link for more th-sas-studio?autoStart true

Using SAS System Options The OPTIONS statement is part of a SAS program and affectsall steps that follow it. It starts with the keyword options andfollows with a list of options and their values. The OPTIONS statement is one of the special SAS statementswhich do not belong to either a PROC or a DATA step. It is a common practice to place the OPTIONS statement atthe very beginning of your program. OPTIONS is a global statement. Any subsequent OPTIONSstatements in a program override previous ones. Example: options leftmargin 1in nodate; Example: proc options; run; /*this prints out all SAS optionsin the SAS log*/

Commonly Used System OptionsThere are hundreds of options for the SAS system. Here is the link to a complete list of all tmThe followings are the most commonly ones:CENTER NOCENTERDATE NODATENUMBER NONUMBERLINESIZE nORIENTATION orientationPAGENO nRIGHTMARGIN nLEFTMARGIN nTOPMARGIN nBOTTOMMARGIN ncontrols whether output is centered or left-justified. Default is CENTERcontrols whether or not today’s date will appear at the top of each page.Default is DATE.controls whether or not page numbers appear on each page of SASoutput. Default is NUMBER.controls the maximum length of output lines. Possible values for n are 64 to 256.specifies the orientation for printing output, either landscape orportrait. Default is portrait.starts numbering output pages with n. Default is 1.specifies the size of the margin (such as 0.75in or 2cm)to be used for printing output. Default is 0.00in.

SAS Data LibrariesIn SAS studio, you will see at least three libraries: WORK library: this is the default library but it is a temporarystorage location for SAS data sets. The work library and itscontents will be deleted after you end the your session. SASHELP library: it is one of the permanent libraries thatcontains information that controls your SAS session along withsample SAS data sets. You can store SAS data sets, SASprograms, and other SAS files here. SASUSER library: similar to the SASHELP library

Listing the Contents of a SAS Data SetAn easy way to get a description of a SAS dataset is using the CONTENTS procedure. You justneed to type the keywords PROC CONTENTSand specify the data set you want with theDATA option. In Example 3 with the contest dataset, we should useproc contents data contest;run;

Description of Data

Practice: Run a SAS sample sessionPlease try both SAS Studio and SAS AcademicOnDemand Enterprise Guide by typing the followingSAS program into the editor window.

Answer the following questions:1) How many statements are there in this program?2) Clearly explain the DATA step and Proc step in thisprogram.3) Briefly describe the information in the log window.4) Try some SAS system options.5) Please write a SAS program to convert temperaturefrom Fahrenheit to Celsius. Use 100 degreeFahrenheit in this program.6) Tell us your experience about using SAS Studio andSAS Enterprise Guide, respectively. Which one do youprefer to use?

Programming Language Rules for SAS Statement To build a SAS data set with Base SAS, we need to write a program that uses statements in the SAS programming language. Here are a few rules for writing SAS statements: SAS statements end with a semicolon. You can enter SAS statements in lowercase, uppercase, or a mixture of the two.