Overview of first steps with sas 1
get a data set into sas format
conduct first analysis of data
This overview describes how to use sas to enter a data set using a short
sas program and then start the analysis using the Sas DMS (Display Manager
System (the sas menu system). (A sas program can also be used for most
analyses).
Setting up your Unix (Mead) session
1. Log in via modem or telnet
Modem dial in
(preferrably using the UW Dial IP Kit Available at the UW Bookstore)
via the phone lines which correspond to your modem speed
see: http://www.washington.edu/computing/connect/index.html
On Campus from a PC or Mac login into Mead or Goodal
or telnet from another computer (use vt100 as the terminal type)
telnet mead.u.washington.edu
2. Unix tools
o the shell
To make handling commands easier (recall commands, edit command line)
use the tcsh (t-shell) either for the session or permanently:
for the session:
mead% exec tcsh
when you are ready to log out you must first type exit to leave the shell.
mead% exit
to make the tcsh (t-shell) the default shell:
mead% chsh
mead1:~> chsh
Changing login shell for......
Old shell: /bin/csh
New shell: /usr/local/bin/tcsh
tcsh commands
up arrow - recall commands going back
down arrow - recall commands going forward
left arrow - scroll left under a command (to change it)
right arrow - scroll right under a command
control a - jump to beginning of command line
control e - jump to end of command line
control u - erase command typed
tab key - try to complete a file name
control d - if on a letter delete the letter
control d - if at end of a command list commands or file names
which match so far
o the editor
You can use any Unix editor, such as pico vi, or emacs. The easiest editor
to start with is pico, the pine composer editor. Use the editor to
create a file of sas code or sas commands. For example to open a file
called 'try1.sas' type:
mead% pico try1.sas
Help for the pico editor is internal via key strokes (^g for help).
(the ^ symbol means the control key... ^x is control x)
and in addition, there is a manual page for pico:
mead% man pico
o other Unix commands:
mkdir make a directory
mead% mkdir mysas
help for mkdir is the manual page:
mead% man mkdir
cd change directory
mead% cd mysas (move to directory mysas)
mead% cd (move 'home' to your home directory)
help for cd is the manual page:
mead% man cd
less a pager, writes a file to the screen one page at a time
mead% less try1.log
less commands are:
space bar - move forward one page
b - move backward one page
carriage return - move forward one line
k - move backward one line
q - quit
/string - search forward for occurrences of 'string'
?string - search backward for occurrences of 'string'
n - find next occurrence of 'string'
N - find previous occurrence of 'string'
help for less is the manual page:
mead% man less
ls list files
mead% ls -lt
-l long output
-t time (most recently touched files first)
help for ls is the manual page:
mead% man ls
rm, cp, mv (remove, copy or rename files)
to erase my.log (and have rm ask for confirmation -i): 3
mead% rm -i my.log
help for rm is the manual page:
mead% man rm
to copy my.sas to another name:
mead% cp my.sas my2.sas
help for cp is the manual page:
mead% man cp
to rename (move) a file:
mead% mv my.sas try1.sas
help for mv is the manual page:
mead% man mv
printing
to print a file to the ACC xerox use prt :
mead% prt my.log my.lst
help for prt is the manual page:
mead% man prt
to print to an attached printer (pc or mac, telnet or modem):
mead% ansiprint my.log
o running a sas program (a file of sas code):
Online help (manual pages and help files)
to find out if there is any thing on a topic use apropos:
mead% apropos edit
to see the manual page for a command use man:
mead% man pico
to get help files (locally written) use help topic or help -l for a list
mead% help commands
mead% help newuser
3. The steps/cycle (without DMS):
The steps:
a) create a sas program with an editor:
mead% pico my.sas
b) run the sas program:
mead% sas my.sas
c) examine the sas program log (my.log):
mead% less my.log
If the log shows errors or problems 4
do step 'a)' and make changes to the file then
re-run the program (step 'b)' and
re-examine 'c)' the log
if all is well you can print the listing file:
mead% prt my.lst
4. Running DMS (Display Manager SAS) via dial in or telnet.
The steps:
a) set two environment variables:
mead% setenv TERMINFO /usr/local/sas609/terminfo
mead% setenv TERMINFOADD /usr/local/sas609/terminfo
b) start sas using the full screen device (fsd) option:
mead% sas -fsd ascii.vt100
This will present a sas log and sas program editor window
o use the program editor to create files of code to submit
or
o use the menu system to submit commands and analyses
to get the command pull down bar type: PMENU on the command line
to start assist type ASSIST on the program editor command line
or from the "globals" pull down...pick assist
(see below)
5. a sample 'session'
goal: to enter data then analyze.
Note: Even if you intend to use sas's menu system to pick commands from
menus...its a good idea to enter your data and make a sas data set
via a sas program. That is, the first step to using sas procedures
is to make a sas data set from your raw data.
I. Get the data into 'sas format'; make a sas data set:
The narrative.
In a sas program to save a sas data set you use the LIBNAME statement
to create a key word or library reference (LIBREF) which points to a place
(directory or sub-directory) which sas should use as the library for sas data
sets. Then on the DATA statement use the libref and a name to save the sas
data set:
filename in 'rain.data';
libname mystuff '~jamieson';
data mystuff.rain;
infile in;
input date rain;
This program writes the sas data set rain.ssd01 to my directory ~jamieson
or on a PC:
libname out 'C:\';
data out.rain;
This writes the sas data set rain.ssd to my PC directory c:\ 5
An annotated (commented) sample program:
/* ~sasclass/saspgms/rdstdat.sas */
/* sas program to read student ~sasclass/data/student.data */
/* save the data as a sas data set */
/* and and print the data for verification */
/* set run options to not center output and not overprint errors */
options nocenter noovp;
/* filename: defines 'in' to represent the raw data file */
filename in '~sasclass/data/student.data';
/* libname creates the library reference 'mylib' to point to a directory */
/* or sub-directory where the sas data sets can be SAVED */
libname mylib '~sasclass/sasdat';
/* data step creates a sas dataset (~sasclass/sasdat/students.ssd01) */
/* the first part 'mylib' tells sas where to save the data (the library) */
/* the second part 'students' names the data set (the library member) */
data mylib.students;
/* infile read the data from 'in' created by the filename above */
infile in ;
/* input describes the raw data file format in terms of sas variables */
/* the dollar sign ($) indicates a character variable */
input name $ sex $ age height weight ;
/* print the data the way sas 'sees' it */
proc print;
run;
Note:
If you want to use a sub-directory use the mkdir command to first
create the sub-directory...then use it in your sas Libname statement:
mead% mkdir sasdat
the relevant program lines:
libname sasdat `~sasclass/sasdat';
data sasdat.rain;
To run the program:
mead% sas rdstdat.sas
If I list the files in the sub-directory I will see the sas data set:
mead% ls -l sasdat
-rw-r--r-- 1 sasclass user 16384 Nov 10 13:55 students.ssd01
To read the data into a program use a libname to point
to the sub-directory where the data set is stored (~sasclass/sasdat):
options nocenter;
libname indat '~sasclass/sasdat/';
proc means data=indat.students;
var age height weight;
run;
The libname refers to the directory or sub-directory where the sas
data set is stored. The data is referred to by its libref (the library
where the data set is stored and the name of the data set (the library member).