| Contents
Debugging Your SAS Program
Debugging a program takes time and will probably require
you to read sections of SAS documentation. SAS documentation
is available online at http://support.sas.com/documentation/onlinedoc/sas9doc.html (SAS
9.1.3 in html or pdf format). Manuals of earlier versions
of SAS products are available for checkout from the Help
Desk, Stephens 201.
Here are some guidelines you can follow when debugging your SAS program.
- Examine the .log file for error messages.
- Look in the SAS documentation for the correct syntax.
- Check for missing semicolons and mismatched quotes.
- Print out part of the data set to be sure that you
are reading the data into the data set correctly. The
SAS commands
proc print data=mydata (firstobs=20 obs=24);
run;
print out all variables starting with the twentieth
observation and ending with the twenty-fourth observation.
- By default, SAS assumes that the record length of
an input record is no longer that 256 characters. If
the record length is longer than 256, include the lrecl option
in the infile statement.
- If there are TABS in the data file, include the expandtabs option
in the infile statement.
- If the data file uses commas as the delimiter between
values, include the dsd option in the infile
statement.
- If the data file uses another character, such as
a semicolon, as the delimiter between values, include
the delimiter=';' option in the infile
statement.
- If you have any missing values, read the SAS documentation
to see how the procedure you want to use handles missing
values. Sometimes an entire observation is eliminated
from analysis if one of its variables contains a missing
value.
- If your program contains many lines of code or many
loops, use comments to help debug the program. Comment
out parts of the program and get subsections working
correctly. The following lines comment out a do loop.
/* do i = ...
...
end; */
- If your program contains many lines of code or many
loops, output intermediate results with the SAS file and put statements.
The following statements output the contents of amount to
the file debug.sas.prog
file 'debug.sas.prog';
put @1 amount 5.1;
put @1 'output from first loop';
- If your program causes your terminal (workstation)
to lock up, then login to anther workstation, rlogin to
the original workstation, and kill the process that
caused the lockup. Useful Unix commands are
| Command |
Action |
| finger yourID |
to see where else you are logged
in |
| rlogin workstation-name |
to access your previous workstation |
| ps -a |
to display your active processes
and their PIDs |
| kill PID |
to kill your process with this PID
number |
- If you are locking up the workstation, you are running
out of memory. If you have created several large data
sets, use proc datasets to delete any data
sets you are no longer using. If you are locking up
the workstation because your log file is too big, you
might have to either save the .log file in /tmp or
not create the .log file at all. Put these
options in sasv9.cfg
- Run a cpu-intensive SAS program in the background
with the sas_batch command.
Type: sas_batch sas_job
You will see a message
Job # xxx started. To cancel it, rlogin to workstation.ucs.louisiana.edu
and type: kill xxx
- When running a cpu-intensive job, also consider
dividing the program into several smaller steps and
saving intermediate results between steps to a file.
For example, suppose that you are generating 5000 numbers for analysis.
Write a macro that generates and saves one number using SAS file and put statements.
Add a do loop to call that macro any number of times, say 500. Run
the do loop program 10 times to generate 5000 numbers.
- If you are reading a very large data file, you can
conserve disk space (not cpu cycles) by having SAS
read a compressed data file.
First compress the file. zip bigfile results in bigfile.zip
To use bigfile.zip as input to your SAS program, include
the following lines in your program.
filename compres pipe 'unzip -p bigfile.zip';
data one;
infile compres missover;
input ...;
additional SAS commands
run;
Back to Contents.
Consulting Help
Contact the SAS consultant for
consulting help.
When a program has errors, it is necessary for the consultant to look
at the SAS program, data file, and SAS log. To send prog1.sas, prog1.dat and prog1.log to
the SAS consultant, type
mail sas < prog1.sas
mail sas < prog1.dat
mail sas < prog1.log
Back to Contents.
Customizing Your SAS Session
You can create two files, sasv9.cfg and autoexec.sas,
that allow you to customize your SAS session during initialization
processing. Put these files in the same directory where
your SAS programs are located. When you execute SAS,
SAS process these two files, and then SAS runs your program.
sasv9.cfg
This file contains valid SAS system option settings
and executes before autoexec.sas file. Examine /pkgs3/sas_9.1/sasv9.cfg to
view an example of a configuration file. SAS executes
configuration files in the following order: first the
SAS default configuration file in /pkgs3/sas_9.1/,
then sasv9.cfg in the home directory, then sasv9.cfg in
the working directory. SAS uses the last value it encounters
for the option.
- If you want to display the listing file on your screen,
include the line
-linesize 80
- If you do not want today's date printed on your listing
file, add the line
-nodate
- If your output or log listings are large, you can
redirect the files to /usr/tmp (temporary
space). First create /usr/tmp/abc1234 directory.
cd /usr/tmp
mkdir /usr/tmp/abc1234
Then include the following lines in sasv9.cfg
-print /usr/tmp/abc1234/prog1.lst
-log /usr/tmp/abc1234/prog1.log
- If you do not want a SAS log file created when you
run your SAS program, add the line
-log /dev/null
Information on other SAS system options is discussed
in SAS Languge Reference: Dictionary and SAS
9.1 Companion for UNIX Environments.
autoexec.sas
autoexec.sas executes after sasv9.cfg and
before the SAS program. It contains valid SAS
statements. Refer to SAS Languge Reference:
Dictionary for a list of valid SAS statements.
Create this file in your SAS directory. If you
frequently use SAS data libraries, create autoexec.sas and
include libname statements of frequently used
SAS data libraries. For example, use a text editor
to create a file called autoexec.sas that
contains the line
libname in '/home/abc1234/sasdir';
Now you do not have to include the libname statement
in your SAS programs that reference the SAS data library in.*
Back to Contents.
SAS Tips
Create graph to display in Adobe Acrobat
Reader on your computer
You can create a graph as a .pdf file, ftp the file to your own computer,
view the graph using (free) Adobe Acrobat Reader, and print the graph
on your own printer.
- Include the following in your SAS program
filename gsasfile '/home/abc1234/graph.pdf';
goptions device=pdf gaccess=gsasfile gprotocol=''
gsfmode=replace handshake=none rotate;
- Run the SAS program and create the file graph.pdf in your
home directory.
- ftp the file to your PC.
ftp ucs_workstation
User: your_ucs_account
Password: your_ucs_password
ftp> binary
ftp> get graph.pdf
ftp> bye
- View the graph.pdf file in Adobe Acrobat Reader. Print the graph.
Note: You can create a graphics file (jpg, cgm) that can be
imported into other software programs (word processing programs, presentation
software, etc). Check with the SAS
consultant for the name of the device driver to use for a particular
software program.
Infile Options
When using the infile command, you can specify options.
infile 'file_name' <options>;
See SAS 9.1.3 Language Reference: Dictionary for a complete
list of options. Some of the more frequently used options are listed
in the following table.
| Option |
Description |
| dlm = ';' |
list data is delimited by semicolons |
| dsd |
list data is delimited by commas |
| expandtabs |
expand tabs to standard tab setting |
| firstobs = number |
begin reading with obs number |
| linesize = number |
limit the record length available |
| lrecl = number |
logical record length |
| missover |
when reading list data, if still have variables
to read in at the end of a line, do not go to the
next line to read in data (set these variables to
missing) |
| obs = number |
stop reading data with obs number |
| pad |
pad with blanks to length specified in lrecl= |
Back to Contents.
SAS Sample Library
/pkgs3/sas_9.1/samples contains directories base,
ets, graph, iml, or, qc, stat. These directories
contain the SAS Sample Library for the various SAS
products. Use these programs to examine examples of
various SAS procedures. For example, suppose you want
to use the SAS/BASE proc means procedure.
Type cd /pkgs3/sas_9.1/samples/base and then
type:
grep MEANS *.* | more
You will see a display on your screen of all files in
the directory that contain the word 'MEANS'. Note: the
programs are written in upper case. You see several references
to 'MEANS' in the means.sas program. If you
do not need to modify the means program then
you can use the program in the samples library. Link
to the program and run it.
ln -s /pkgs3/sas_9.1/samples/base/means.sas means.sas
sas means
means.log and means.lst are written
to your working directory. If you want to modify the
program, copy means.sas to your SAS directory.
cp /pkgs3/sas_9.1/samples/base/means.sas means.sas
sas means
Modify, run, and examine the SAS log and listing files.
Refer to the documentation for proc means if
you are unsure about the syntax.
Back to Contents.
SAS Newsgroup
SAS-L has a FAQ (Frequently
Asked Questions) and searchable archives.
You can also subscribe to comp.soft-sys.sas and read the latest SAS-L
newsgroup postings.
Back to Contents.
WWW Sites
The SAS Institute web
site contains a great deal of information. In particular, SAS
Customer Support Center includes various sources
to help you solve problems. For example, you can search
the entire support site, you can search SAS Notes (primary
source used by the SAS Technical Support Consultants),
and you can also view code samples.
Numerous other sites contain statistics and SAS information. To locate
the most current information use a web search program such as Google.
Back to Contents.
FTP Server
The SAS
FTP server contains files of interest to SAS users
such as technical information and sample programs.
Back to Contents.
Types of SAS Files
Different types of SAS files serve different functions.
SAS automatically assigns a certain extension to each
file when it creates the file. The file extension determines
the function as the following table shows.
| File Extension |
Description |
| .sas |
SAS program (user defined) |
| .lst |
SAS procedure output file |
| .log |
SAS log file |
| .sas7bdat |
SAS data file |
| .sas7ndx |
Index for SAS data file |
| .sas7bcat |
SAS catalog file |
| .sas7bpgm |
SAS stored program |
| .sas7bvew |
SAS view file |
Back to Contents.
Additional Information
For additional information, contact the Help
Desk,
Stephens Hall 201; 482-5516.
|