SAS on demand for academic use
[beginning Fall 2010, updated August 2014]. Also there is a
SAS University Edition.
There are two versions available free for academic use.
- SAS (version 8.2) is available only on the unixlab.stat.ubc.ca (or
[no longer available as of September 2013];
- The Unix command is 'sas' or click on the SAS button after
login to get to the Windowing environment.
- By default, this will bring up the X-windows interface,
which includes a Toolbar, a program editor, etc. The Unix port is
not as good as the Windows port, because there are too many separate
windows rather than one cohesive window.
- 'sas myprog.sas' will apply SAS to the program myprog.sas,
and produce myprog.log (log/error file) and myprog.lst (output
file if there are no errors).
- SAS can be used in both menu-driven (GUI) and batch (programming) modes.
In some of the GUI applications, one can ask for the
output of the SAS code.
- For graphical methods, include rotating 3-dimensional plots,
in Program Editor Window -> Solutions -> Analysis ->
Interactive Data Analysis. Or type "insight" in the Toolbar.
- For statistical methods such as regression and ANOVA,
in Program Editor Window -> Solutions -> Analysis ->
Analyst. Or type "analyst" in the Toolbar.
Then under Statistics in the Analyst window, listed are:
Descriptive, Table Analysis, Hypothesis Tests, ANOVA, Regression,
Multivariate, Survival, Sample Size.
- (In Unix), the SASHOME directory is /usr/local/sas; examples that come
with the installation are in /usr/local/sas/samples.
/usr/local/sas/samples/base has basic examples.
/usr/local/sas/samples/stat has examples for statistical methods.
/usr/local/sas/samples/ets has examples for econometrics time series.
One can apply 'grep' to search for examples by keywords.
Alternatively, the examples can be found somewhere under Help, after
bring up SAS in the windowing environment.
- There is on-line documentation but for beginning SAS users, it may be
easier to consult old SAS manuals.
The most useful manuals may be SAS/Basics, SAS/STAT, SAS/IML.
You can also try v8doc.sas.com/sashtml/
for documentation and examples.
Remote access from MacOSX or Windows
Instructions for access to Unixlab
from a remote computer running MacOSX or Windows.
Importing data sets to SAS
- A data set can be read in through a DATA paragraph; in this case, the
default field delimiter is one or more spaces. An example is at
here ; this example also saves the
data set (in a library/directory) into SAS internal format so that it will
appear in the SAS data set browser.
- A data set can also be imported through the ImportData menu under
the File tab (say, Program Editor window).
- From the ImportData window,
select a data source (e.g., comma delimited .csv or delimited file;
in Windows but not Unix, excel file .xls is one option).
- Select .csv for comma delimited and delimited file for (single) space
delimited; use browser to select your file. The Import Data facility
fails if there are multiple spaces as delimiters.
- Check the Options button: SAS can figure out if you have
variable names in the first row, in which case the options menu shows
"first row of data" as 2. Note that SAS truncates variable names to 8
characters so make sure your variable names are unique in the first 8
- Select library (WORK is temporary library for current session only,
other libraries specified through configuration file which is autoexec.sas
in Unix) such as s541
- Select SAS data set name if overwriting previous file, otherwise
enter new SAS data set name (this need not be same as original file name
-- note that SAS likes names to be 8 letters or fewer).
- Finally, you have the option of saving the SAS code for the data
set importing. If you do this, you will see the PROC IMPORT is used.
- Check from InteractiveDataAnalysis (under Solutions->Analysis)
that the data set was imported correctly.
Permanent SAS library
- List of simple SAS examples
for statistical methods for prerequisite courses, also link to basic
SAS syntax and use from editors.
- Introduction to SAS/IML (interactive matrix
- SAS examples from previous course in 2002
- SAS 9 has Output delivery system (ODS) which means selected tables
can be printed rather than all tables, and selected output components
of a PROC can be saved to use for further calculations in
PROC IML (this is like data structures or objects in Splus/R).
See listing under next bullet for examples
- SAS examples previous course 2006
: examples on creating SAS data sets,
ODS, IML, ETS and interactive time series forecasting system.
If you have never used SAS before, below are some comparisons.
Advanced features of SAS are SAS/IML and macros.
Why learn SAS
- No statistical software can do everything. For example,
features of SAS not in R: sophisticated econometrics/time series
analysis; proc nlmixed for non-linear mixed models; database management
and SQL; etc.
- Enhance your job prospects: many statistical jobs in pharmaceutical and
government agencies require SAS programming.
- Speed of computations: SAS is much faster than R and Splus
(but an order of magnitude slower than C/Fortran; see some
comparative speeds below.
Is SAS more difficult to learn than R?
- If you have programmed in one language and understand the general
principles of programming, it should be relatively easy to learn
another programming language.
- Although SAS does have an interactive mode based on a prompt, e.g. in
SAS/IML, the Interactive Matrix Language, the interactiveness is not as
nice as Splus/R. But this is the tradeoff of speed and interactiveness;
a software that has a nicer "interactive" interface is slower to run
for computing intensive tasks.
Speed comparisons of SAS with R and C
These comparisons are made by timings on a common computer.
The computational task was an iterative loop of one million
cycles to evaluate a probability by simulation.
Order of speed is:
C, SAS, matlab, R, octave (matlab clone in Unix).
Splus is typically much slower than R for loops.
- C is about 4.7 times faster than SAS,
161 times faster than matlab,
200 times faster than R,
and 355 times faster than octave.
- SAS is about 44 times faster than R,
and 35 times faster than matlab.
For use of a single SAS procedure or R function,
the timing will likely be equivalent to the speed of C, because
the actual computations will be based on compiled C or Fortran code.