Session 1:
Introduction to The SAS System
page
Notation Conventions used in the course 1-1
An overview of the SAS System 1-1
Places to go for help with SAS 1-4
The SAS Windows 1-6
Practical Session 1 1-9
1. Retrieving data & some simple analysis 1-9
SAS Libraries 1-9
Creating your own SAS library 1-9
Viewing a data table 1-11
The Analyst Application 1-13
Starting a new Analyst project 1-13
Setting output preferences 1-15
Frequency counts 1-15
Viewing your output 1-16
Saving your work in Analyst 1-18
Printing from Analyst 1-18
2. Creating a SAS Data File Using the Data Editor 1-19
The data 1-19
Defining the variables 1-19
Entering the data 1-22
Saving the data 1-22
Some descriptive statistics 1-23
Appendix : Some SAS Code 1-25
SESSION 1: Introduction to The SAS System
Notation Conventions used throughout the course
1. These notes use either of the following conventions
Menu topic
Item
Item
or
Menu Item Ø Item Ø Item
to indicate that a sequence of 3 clicks are nested.
2. When following through the demonstrations, a bullet point indicates that
action is required, e.g.
§ Now do this
An overview of The SAS System
Before we get started it is worth mentioning that SAS Software is an integrated,
hardware-independent system of applications software that is built up of a
series of selected modules. A brief description of the modules available are
given below (these descriptions taken from the SAS help menu – more details
available there). Some of the modules are core modules (Base SAS,
SAS/STAT) whilst some simply provide a tailored interface to specialist
procedures (SAS/Insight, SAS/Lab, SAS/Analyst).
Modules available at Lancaster are marked with a *.
Base SAS* The main core of the SAS system, needed on which to build
any other module.
OLE DB Providers interfaces that can read data from a variety of sources using
the OLE Component Object Model
1-1
SAS/ACCESS* a family of individual interfaces that provides direct and
transparent read and write access to many databases on
several platforms. At Lancaster we have access to PC File
Formats (Excel, MS-Access) and ODBC
SAS/AF an object oriented application development facility used to
create custom, interactive, extendible graphical user interfaces.
SAS/ASSIST* The original menu-driven interface to many of the SAS System
tools, such as data analysis, report writing, graphics, and more.
Now rather superseded by Analyst and Insight.
The Analyst Application a user-friendly interface (integrated into the SAS system) to
access a range of data manipulation, graphics and statistical
analysis tools.
SAS/CONNECT a SAS-to-SAS client/server tool set for creating & managing a
distributed networks of users.
SAS/EIS a code-free version of SAS/AF
SAS/ETS* data analysis component for Econometrics and Time Series
techniques.
Enterprise Guide client software that gives access to reports and graphics using
point-and-click operations. It can be used as a separate front-
end to the core SAS software.
Enterprise Miner a project based SEMMA (Selecting, Exploring, Modifying,
Modelling, and Assessing) approach to data exploration
including a range of data mining techniques.
SAS/FSP* convenient interactive facilities for data entry, editing, browsing,
retrieval, and form-letter writing (facilities that are now
integrated into the main SAS System)
SAS/GIS a variety of tools, features, and capabilities that are specific to
the business geographics market
SAS/GRAPH* the graphics component of the SAS System including a wide
range of graphs and charts
SAS/IML* an interactive matrix programming facility
SAS/IML Workshop a graphical user interface for matrix programming and
exploratory graphics. (Beta release can be downloaded from
the SAS web site)
SAS/INSIGHT * an interactive tool for data exploration and analysis; users can
examine distributions and explore their data through interactive
histograms, box plots, scatter plots, and 3D rotating plots as
well as building a range of predictive models.
1-2
SAS/IntrNet a suite of tools that allow you to create and deploy Web-
enabled applications. The dynamic applications provide remote
access to your data and bring the computing power of SAS
software to any desktop, regardless of whether SAS software
is installed.
IT Service Vision a performance evaluation tool that allows you to analyze IT
resources more effectively.
SAS/LAB provides guided data analysis for meeting the day-to-day
analytical and data presentation needs of engineers and
research scientists. Commonly required capabilities for
analysis or variance, analysis of covariance, and regression
analysis are closely linked with graphical tools that produce
scatter plots, histograms, box-and-whisker plots and contour
plots.
SAS/MDDB Server enables users to create and manage multi-dimensional
databases (MDDBs) to provide fast and easy data access by
tools such as multidimensional data viewers.
SAS/OR* a project management, optimization and decision support tool.
SAS/QC a variety of specialized tools for establishing statistical quality
control and reducing variability.
SAS/SHARE created for multi-user environments, such as sales
management or purchasing, in which users need concurrent
access to information.
SAS/SPECTRAVIEW an interactive, volume visualization tool for viewing, exploring,
and analyzing multidimensional data. Including the creation of
two- and three-dimensional graphic images of the data set.
SAS/STAT* the integral component of the SAS System, providing the
statistical capabilities for many of the other modules.
SAS/TOOLKIT allows SAS users to write their own SAS procedures, functions,
formats and informats, providing support for FORTRAN and C
(for Windows & Unix users).
Warehouse Administrator provides a visual environment for managing data warehouses
1-3
Places to go for help with SAS :
SAS main Web pages : www.sas.com (but be warned that it does take some
practice to navigate around these !)
Web Tutorials : http://www.sas.com/service/edu/courses/tutorials.html
These include ‘Getting Started with.. ‘ guides to :
The SAS System (see description below*)
Enterprise Guide
Enterprise Miner
SAS/EIS
SAS/GIS
Tutorials from within SAS :
*Getting Started with SAS
This is the same tutorial that is available from the SAS web pages and
covers aspects of The Base SAS System as well as including a very brief
section on The Analyst application. Be careful to note the modules that
are required to perform some of the techniques described.
Introduction to SAS Programming
If you also have Explorer 5 or Netscape Navigator 4.07 (or later versions)
Web browsers on your machine you can use the On-line tutorials from
within SAS. From the menu bar select Help Ø Books & Training Ø SAS
Online Tutor. Note that it takes a few moments for SAS to prepare the
data files needed, and SAS will then open Explorer/Netscape and you can
follow the tutorial from there. This tutorial will tell you how to use SAS code
rather than simply using the drop-down menus.
Enterprise Miner
If you have Enterprise Miner installed on your machine, you can get more
information on nodes and process flow, plus a glossary of data mining terms
from materials in the Help system. From the menu bar in Enterprise Miner,
select Help Ø EM Reference Ø Getting Started with Enterprise Miner.
JISCmail : An e-mail based system for sending messages/queries/ details of
updates etc. to other members. For use by any member of the
academic community who wishes to join. For details of how to
join the SAS list see the JISCmail web site at
http://www.jiscmail.ac.uk/default.htm
1-4
Books : Delwiche L.D. and Slaughter, S.J. (1998), The Little SAS Book,
SAS Institute Inc.
Aimed at people with no prior knowledge of The SAS System this introduces you to
the SAS command language, including topics such as data import and export,
manipulating and summarizing data, modifying and combining data sets, and a brief
introduction to some basic statistical procedures such as simple linear regression
and one-way ANOVA. It doesn’t delve deeply into any one are but gives a good
introduction to some basic SAS concepts.
Everitt B.S. and Der G. (1996), A Handbook of Statistical Analyses
using SAS, Chapman and Hall.
An introduction to the SAS command language. Covers basic data input, and
introduction to statistical techniques: multiple regression, analysis of variance,
analysis of repeated measures, logistic regression, survival analysis, principal
components and factor analysis, cluster analysis, discriminant analysis and
correspondence analysis. Treatment is brief, the user is assumed to be familiar with
the techniques. Uses data sets from A Handbook of Small Data Sets available on
disc.
Cody R.P. and Smith J.K. (1997), Applied Statistics and the SAS
programming Language, Prentice Hall.
A more comprehensive treatment of the SAS command language. Data entry and
manipulation is covered in some detail. Statistical techniques covered: regression, t-
tests, analysis of variance, repeated measures, multiple regression, factor analysis,
psychometrics. Advanced programming topics include merging information, using
arrays, character functions and sorting.
Larose D.T. and Jin C. (1998), Ready, Set, Run! : A Student Guide
to SAS Software for Microsoft Windows, Mayfield Publishing
Company.
A basic introduction to SAS for Windows. This is for SAS version 6, so still uses the
command language interface. This is a very basic introductory text,
very basic data entry, and covers descriptive statistics, graphics, t-tests, ANOVA,
linear regression and chi-squared test.
SAS On-line
documentation : SAS on-line documentation is a subset of the SAS reference
manuals and user guides, made available electronically in
html format – so can be read by any Web browser.
At Lancaster a copy of the CD can be bought by staff and
students from ISS reception. A copy is also available on-line
over the server by connecting a network drive (say N:) to
\\central_soft\netapps and running
N:\SASdoc8\sasdoc\sashtml\onldoc.htm
1-5
The SAS Windows
When you start up SAS , the opening screen should appear as below.
Note that the menu options and toolbars change as you move around the SAS
system.
In particular
take care
when saving
files.
Which file
you actually
save will
depend upon
which
window is
active.
As windows are minimised they appear in the strip at the bottom of the main SAS
window.
The screen consists of the five main SAS Windows - the Explorer,
Results, Editor, Log, and Output windows.
1-6
1. The Explorer Window
In the Explorer window, you can view and manage your
SAS files and create shortcuts to non-SAS files. Use this
window to create new libraries and SAS files; open any
SAS file; and perform most file management tasks such
as moving, copying, and deleting files.
Selecting View
Show Tree
from the Explorer menu bar allows you to choose to
display the Explorer window with or without a tree view of
its contents.
2. Editor Window
In the Windows operating
environment, you can use
one or more Editor
windows to enter, edit, and
submit SAS programs.
Note that there are 2 types
of editor : the standard
editor or the enhanced
editor.
The enhanced Editor provides a number of useful editing features, including
• color coding and syntax checking of SAS language
• expandable and collapsible sections
• recordable macros
• support for keyboard shortcuts (Alt or Shift plus keystroke)
• multi-level undo and redo
and much more.
1-7
3. The Log window
The Log window displays
messages about your SAS
session and any SAS code
you submit.
4. The Output Window
In the Output window, you
can browse output from SAS
code you submit.
By default, the Output
window is positioned behind
the Editor and Log windows.
When you create output, the
Output window automatically
moves to the front of your
display.
5. The Results Window
The Results window helps you navigate and manage the output from SAS code
which you submit. You can view, save, and print individual items of output.
By default, the Results window is positioned behind the Explorer window and
is empty until you submit a SAS program that creates output. Then it moves to
the front of your display.
1-8
Practical Session 1 :
1. Retrieving data and running a simple analysis.
In this exercise you will retrieve an SAS data file and carry out a simple
analysis. This exercise will allow you to become familiar with the main SAS
windows.
Starting SAS
§ From the Start menu in Windows NT, select
Program
The SAS System
The SAS System for windows V8
SAS Libraries
SAS files, such as tables (data) and catalogs, are stored in libraries. By
default, SAS software defines several libraries for you (including Sashelp,
Sasuser, and Work). You can also define additional libraries.
When you define a library, you indicate the location of your SAS files to SAS
software. When you delete a SAS library, the pointer is deleted, and SAS
software no longer has access to the directory. However, the contents of the
library still exist in your operating environment (e.g. hard disks). Once you
create a library, you can manage SAS files within it.
Create your own SAS library
§ Use the mouse to male the Explorer window active (click anywhere in the
Explorer window)
§ Double click on the ‘Libraries’ icon
The Explorer window should then show the current active libraries.
§ In the Tool bar click to create a new library.
1-9
§ In the New Library
Window, name the new
library as coursdat.
§ Click in the check-box to
select Enable at start
up. (SAS will then
remember this library
definition each time it
starts).
§ In Path give the directory
and file name where the
course data are stored C:\SASdata ).
§ Click on the OK button.
The Coursdat library should now appear in your
Explorer window as shown here.
§ Double click on the Coursdat library icon.
In the Explorer window you should now see the all the SAS data
that we use in this course.
1-10
Viewing a data table
§ Double click on the icon for Bsas91
The Viewtable window should now be opened and filled with data from the file
BSAS91 as shown here.
The variable names or descriptions (labels) appear in boxes along the top and
the row number or cases appear down the left hand side, numbered
sequentially. In the lower right-hand corner are the scroll arrows, and .
Click on these, to see more variables and/or cases.
The variable labels can be displayed or not by
selecting Either ‘Column labels’ or ‘Column names’
from the View menu.
1-11
By double-clicking on each variable name (at the top of the column), we can
see the details of that variable in the Column Attributes. We can change the
name, label, format and
other attributes of this
variable in this window.
§ Find the variable
DOCHORE2 and double-
click on the column
heading to get the
Column attributes
window.
§ Look at the options
available under the
heading General, Colors
and Fonts by clicking on
the tabs at the top of the
window.
§ Click Apply then Close if you have changed anything or simply Close if
you have not.
Now close the view table….
§ Make sure that the data table window is active (selected) and select
File
Close from the menu bar.
1-12
Analysing your data (The SAS Analyst application)
The Analyst Application provides easy access to commonly used statistical and
graphical analysis capabilities. Here we learn how to start a project, select data,
and set preferences.
Starting a project
§ From the menu bar select
Solutions
Analysis
Analyst
A new project will be created in a new window, as shown below.
1-13
§ With the Analyst window active, select
File
Open By SAS Name from the menu bar.
§ Under Libraries, select Coursdat.
§ From the list of data files select Bsas91
§ Click on the OK button.
All the variables in the BSAS91 file should now be displayed in the Analyst
Window in Browse mode.
The BSAS91 data appear in the table, and a node for the BSAS91 data is
added to the tree under New Project.
1-14
Setting preferences
You can set a number of preferences for your project. In this example, you
choose to display the programming code generated for each analysis.
§ From the menu bar select
Tools
Viewer Settings
The viewer settings dialog box should appear..
§ Click on the Output tab
§ If Create HTML file of
results is selected, click on
the check-box to de-select
this option.
§ Select Display graphs with
scroll bars
§ Select Provide source code
§ Click on the OK button.
Now you are ready to perform analyses in the Analyst Application.
Frequency Counts
§ From the menu bar select
Statistics
Descriptive
Frequency Count
§ You can now do one of two things:
1. single click MARSTAT which should highlight it and then click on
Frequency.
2. double click the variable MARSTAT
Either of these actions should achieve the same end: the variable MARSTAT
(R’s marital status) should appear in the Frequencies box as shown on the
next page.
1-15
§ Click on the Plots button.
§ In Bar Charts select
Vertical and click
OK.
§ Click on OK to perform the analysis.
Viewing your output
The results should appear in a window labelled 1-way frequencies of Bsas91.
1-16
§ For now, minimize the 1-way frequency of Bsas91 window (click on the at
the top right of the window).
§ In the Analyst Explorer Window double click on Vertical Bar Chart to get
the Bar Chart of MARSTAT shown below.
Bar chart of MARSTAT
§ Click on the symbol to scroll through your output. (Note that for graphics
windows this only works sensibly if the window is maximised).
1-17
Saving your work in Analyst
In the Analyst explorer, each result is displayed in a separate window.
You can therefore save each individual result (output window) as a separate file
or save the entire project.
To save an individual output window …
1. Make that window the active window.
2. Select File
Save As from the menu bar
If the output is a table or textual summary of results SAS will save it in text
format by default.
If the output is a chart or graph, the default output type is a GIF file but you can
also choose to save it as a JPEG or Postscript file.
To save the entire project …
Select File
Projects
Save from the menu bar.
Printing from Analyst
Within Analyst you can only choose to print an individual window at a time.
To print an individual output window …
1. Make the window you want to print the active window.
2. Select File
Print from the menu bar.
Another alternative therefore is to copy and paste your results from SAS into a
word processor, such as Word, and print the results from there. With graphics it
is probably safer to save the graphic first and import it to the word processor as
a GIF or JPEG file.
1-18
2. Creating your own SAS Data File Using the Data Editor
The data
In this exercise you will create a new data set, defining your own variables and
entering some data collected about 10 visiting students. The pieces of
information were collected …
1. Surname of student
2. Sex of student
3. Distance travelled to the University
Once entered you can then get some summary statistics about the distance
travelled by the students.
Defining the variables
§ Start SAS in the usual way.
§ Select Tools,
Table Editor from the menu bar.
This opens the
Viewtable
window
§ Right-click (i.e. use the right-hand mouse button) on the first column (A).
1-19
§ Select Column Attributes to get the following dialog box
§ In the Name
box, type the
variable
name, e.g.
‘surname’.
§ In the Label
box, type the
variable
label,
Participant’s
surname.
§ In the Type box, select the Character button. (This allows you to enter the
surnames as letters, rather than numbers.)
§ In the Length box, type the variable’s length 15. This is how many
characters your variable is allowed to be. The rest will be filled as default.
§ Click on the Apply button and then on Close.
The variable name should appear at the top of column A.
The variables sex and distance can be defined in a simpler way because they
are numeric variables.
§ Right click on column B to define sex in this column, and again select
Column attributes from the menu.
§ In the Type box, select Numeric. By default the SAS system choice ‘best’
notation will automatically apply to Format and Informat . To change these
to your ideal format click on the button to the left of the format box.
You can select any number of formats from here. We will be looking at formats
in more detail in session 4.
1-20
§ For now leave this as the default :
click on ‘best’.
§ Now define the final variable distance in column 3 , as a numeric variable.
Your data table should look like the one below, with all 3 variable names at the
top of the columns.
1-21
Entering the Data
§ Simply click your cursor in the first cell and start typing in the names and
numbers.
§ Use the backspace
(ç) key on the
keyboard to delete any
mistakes and replace
with the correct
numbers.
§ Enter the data as
shown (or make some
up !)
Saving the data
§ Save your data as a SAS Data file by selecting
File
Save
from the main menu bar.
§ Click on the Coursdat
library
§ Select a name for your
file e.g. Distance
§ Click on the Save button
§ Close your Viewtable by selecting
File
Close
from the main menu bar.
1-22
Some descriptive statistics
To find out the average distance the students travelled we are going to use
SAS Analyst once again.
§ From the main menu bar select
Solutions
Analysis
Analyst
§ With the Analyst window active, select
File
Open by SAS Name
§ As you have done before, select the Coursdat library from the list of
libraries and your Distance data from the list of data sets.
The data should now appear in the Analyst data table
§ From the menu select
Statistics
Descriptive
Summary statistics
§ Select distance
from the list of
variables
§ Click on the
Analysis button to
transfer this variable
into the Analysis list.
§ Click on OK.
1-23
§ When SAS has finished processing your commands, inspect your results in
the Summary Statistics of distance Window.
§ Repeat the analysis but
this time select some of
the other options
available with summary
statistics using the
Plots and Statistics
buttons.
Exiting Analyst & SAS
§ Select.. File
Close to close the current active window (the Analyst project)
§ Select.. File
Exit to close SAS
1-24
Appendix 1 : Some SAS Code
The file ‘session1.sas’ stored in the directory C:\sasdata contains examples of
some of the techniques covered in this session. A copy is shown on the next
page.
To try running the commands…
§ Make the Program Editor window the active window
Select View
Enhanced Editor from the menu bar.
§ Open the file ‘session1.sas’, stored in the directory C:\sasdata by selecting
Select File
Open from the menu bar.
§ Submit the commands to SAS by
either
Clicking on the submit tool , , on the tool bar
or
Selecting Run
Submit from the menu bar.
1-25
* Session1.sas;
* The next command defines the library coursdat
* This library reference will last only for the
* duration of this SAS session;
libname coursdat 'C:\sasdata';
* Example from Exercise 1
*
* To perform a frequency count of the variable DOCHORE2 from the
* data set BSAS91 use the FREQ procedure as follows ..;
PROC FREQ Data=Coursdat.BSAS91;
TABLES DOCHORE2;
RUN;
* Example from Exercise 2
*
* To create the data in exercise 2 use a DATA step .. refer to the data
set
* as 'lib-ref.filename', i.e. coursdat.distance
*
* The DATALINES command tells SAS that the data is
* included in the program
*
* The $ indicates that the preceding variable is not numeric;
DATA coursdat.distance;
INPUT Surname $ Sex Distance;
DATALINES;
Brown 1 12
Smith 2 15
Robinson 1 93
Fligelstone 2 1
Green 1 12
Harris 2 6
Jenkins 1 25
Johnson 2 42
Frank 1 3
Stone 2 11
;
RUN;
* To perform the Summary Statistics use the MEANS procedure;
PROC MEANS data=Coursdat.Distance n mean std min max;
var Distance;
RUN;
1-26