Introduction to SAS

If you have questions about SAS courses or about how to get help on SAS, please contact SAS directly. These pages provide local information that might be of broader use. Please send comments, suggestions, additions or corrections on THIS document to Return to SAS Information or Computing Facilities.

Using SAS on a UNIX System

While SAS can be run interactively, it is still easiest (and safest) to run in "batch" mode. Therefore, you must be familiar with the use of files on your computer system. Basically, a file is like a piece of paper in your notebook or a chapter in a book; a directory is like the notebook or book itself. Here are a few examples of program calls on UNIX, our platform (the prompt % is typed by the computer):
% cp file1 file2	make a copy of file "file1" named "file2" 
% more file		look at "file" a page at a time
			(use long space bar to page forward)
% ls			list names of your files in your directory
% ls -l			long version of "ls" (has dates of last change)
% emacs file		edit "file" using full screen editor "emacs"
% vi file		edit "file" using full screen editor "vi"
% rm file		remove "file" from your directory
While it is more efficient in the long run to learn an editor (emacs or vi) on our sytem, it is also possible to work from your local computer and use FTP (that is, Fetch from WiscWorld) to move files back and forth. There are on-line manual pages for commands. For instance, type man rm to find out more about the rm command. There are several good books on UNIX listed on the UNIX Systems page.

The easiest way to run SAS is to store your commands in a file and then pass that file to the sas program. You can either copy one of your instructor's examples, or create your own using emacs or vi. It is a good idea to get in the habit of using the .sas suffix to identify a file of SAS commands. Other standard suffix conventions include:	sas command file (may have data also)
myfile.dat	data file (if separate from "")
myfile.log	log of what sas did with your commands
myfile.lst	output listing of your successful commands 
The myfile name is up to you; use 8 or fewer characters in the name, starting with a letter (a-z). Numbers (0-9) or underscore (_) can be used, but avoid other symbols. (This naming convention applies to SAS variables and datasets as well.) The sas program automatically produces the myfile.log and myfile.lst files for you. All you have to do is type the command
% sas
Usually it takes a little while to run. If instead of giving your file you simply typed
% sas
the computer goes into "interactive mode". This is rather complicated and best left to advanced (or adventurous) users. Avoid for now. If you do type this by mistake, simply type the following:
(Those are semicolons, the key just to the right of the L key. Follow by a RETURN.) This will get you out of SAS safely. Otherwise, yell for help!

NOTE: Always review the log file before looking at the output listing. It is usually short. Lines with NOTE: are fine and can be helpful in tracing transformations and creation of new variables. Lines with ERROR or WARNING should be heeded: look for the problem somewhere ABOVE the identified line.

SAS Language

Examples of SAS can be found The usually contains three kinds of sas "paragraphs" or "steps", namely:
options		printer options
data		data input, transformation and manipulation
proc		procedures for plotting, regression, etc.
The options, data steps and some procs (numerical and graphical summaries, plots) are described in the SAS/BASICS book. The other procs (regression, analysis of variance and other fancy stuff) are found in SAS/STAT. SAS reads your file in "free" format--use as many spaces or tabs as you like--but requires a semicolon (;) at the end of each "phrase" or "sentence". It is good practice to indent phrases in data or proc "paragraphs" for ease of reading.

Comments can appear anywhere in your program EXCEPT in the middle of data. Comment lines can begin with an "asterisk (*). Alternatively, a comment paragraph can be surrounded by "slash asterisk" (/*/*) and "asterisk slash" (*/).

* this is a comment line
/* this is also a comment line */

OPTIONS can only appear as the first line of Here is a setup for looking on the screen:

options nocenter linesize=80 pagesize=24;
Nice size printer plots do better with the option pagesize=50. Common options include:
   nocenter	do not center output (flush right instead)
   linesize=80	set width of page to 80
   ls=80	same as linesize
   pagesize=50	set length of page to 50
   ps=24	same as pagesize

Return to U WI Statistics Home Page

Last modified: Tue Jul 25 12:36:05 1995 by Brian Yandell Tue Feb 14 11:10:04 1995 by Stat Www (