Useful Options For Every SAS Program – Lessons and Resources from Dr. Jerry Brunner
June 24, 2014 Leave a comment
Today, I want to share some useful options to put at the beginning of every SAS program that I write. These options will make the practicality of using SAS much easier. My applied statistics professor from the University of Toronto, Jerry Brunner*, taught me some of these options when I first learned SAS in our class, and I’m grateful for that. In later instances of using SAS in team projects, I have met SAS programmers who were delightfully surprised by the existence of these options and desperately wished that they had learned them earlier. I hope that they will help you with your SAS programming. I have also learned some useful options by posting questions on the SAS Support Communities online forum.
After running your SAS program many times to test and debug, you will have accumulated numerous pages of old and useless output and log. Scrolling through and searching for the desired portion to read in either file can be tedious and difficult. Thus, it’s really helpful to have the option of clearing all of the output and the log whenever you run your script. I put the following commands on top of every one of my SAS scripts.
/* Useful Options For Every SAS Program - With Some Tips Learned From Dr. Jerry Brunner by Eric Cai - The Chemical Statistician */ dm 'cle log; cle out;'; ods html close; ods html; dm 'odsresults; clear'; ods listing close; ods listing;
These first 6 lines of code ensure that the output window, the log, and the results window are all cleared before any of the subsequent SAS code is run.
Making the Log and List File Easy to Read
The following block of code is helpful for reading the log and the list file, especially if you use SAS in Unix and you are reading the log or the list file on the terminal screen (i.e. without the neat organization by the SAS Display Manager when using SAS in Windows).
options noovp linesize = 79 formdlim = '-' pageno = min ;
- One option for identifying errors in the log file is the overprinting option, or ovp. If you turn this option on, then any wrong part of your code in the log will be overwritten by underscores (like ___). This may look fine in the log when shown in the SAS Display Manager in Windows, but these underscores can make the log very hard to read when shown in Unix on a terminal screen. When I was a student at the University of Toronto, I used SAS in batch mode in Unix, so I always turned the ovp option off by writing noovp in my list of options at the beginning of every script.
- The linesize option specifies the maximum number of characters that SAS will display on each line in the log or list file. The default line size depends on the printer resolution and printer font, but it could be far more than what the width of the common 8.5-inch-by-11-inch paper allows. Thus, through trial and error, Dr. Brunner recommended 79 characters as ideal.
- By default, SAS will print a new page for every new section of output. This could result in many pages with very little output and a lot of space, and it also makes the list file very hard to read. The option formdlim will prevent this and simply separate different sections of the output by a delimiter of your choice. I like using the dash (-).
- The pageno option ensures that the page numbers in the list file start from 1 on the first page whenever a SAS script is run. This may sound like an obvious option to have, but, by default, SAS remembers the page numbers from previous runs and simply continues the page numbers from previous runs on the current runs. I like having the page numbers reset to 1 on the first page whenever I run a script, so I always include this option.
What are your favourite SAS options for making your SAS programming effective and efficient? Please share them in the comments!
- Dr. Brunner is a very smart guy who is good at teaching and very approachable to students who seek his help and advice.
- I learned many valuable things about applied statistics from him, and they have become useful in my career as a statistician in industry. (He has collected much of his teaching material into a free and open-source book called “Data Analysis with SAS“.)
- He assigned homework problems in both R and SAS, forcing us to learn to use both of these popular programming languages for statistics. Our course web site had many valuable resources for learning both languages that I still use to this day, more than 2 years since I finished his class. Unfortunately, most academic statisticians don’t use SAS, so many students don’t get training in SAS during their graduate studies. If you are a statistics student who is looking for a job, I highly encourage you to learn SAS – many employers expect you to be proficient at it. Had I not learned to use SAS in Dr. Brunner’s class, I would have struggled in my jobs in statistics so far.