SAS Files

Doug Hemken

December 2017

SAS Notes

Overview of SAS Files

As with most statistical software, working on a project in SAS will typically mean working with several different files. The basic workflow will be to submit your SAS commands and data to the SAS processor. SAS interprets your commands, a block of code at a time, and produces the desired results: a log of the commands executed, any statistical tables or graphs requested, and any data modifications requested.

SAS Workflow
SAS Workflow

The different types of input and output are saved as separate files. Saving your commands and logs works pretty much the way you expect it to: you make the appropriate window active, then click File -> Save in the menus. Saving your data or statistical results is best done by writing the appropriate code, so this is a little less intuitive (we’ll come back to the details, later).

SAS File types

Most files can be named whatever you like. However, data files are most gracefully handled if their names are one-word, alpha-numeric names, i.e. avoid spaces and most special characters in data set names.

Command Files (*.sas)

Command files should have a file extension of ".sas". These are saved via the menus by clicking File -> Save.

Files with SAS commands are saved as simple text. In principle you could create or view these with any text editor, but most of us find it easiest to set them up using the Enhanced Editor within SAS - the color coding helps you spot typos quickly, and you can test your code as you go by submitting selected blocks.

Data Files (*.sas7bdat)

Data files should have a file extension of ".sas7bdat". These are usually saved as part of a DATA command, a DATA step. More on the details, later.

SAS can read and write data from/to a variety of formats, but to process the data SAS must have it in it's own SAS format. It is usually convenient to save data in this format.

Log Files (*.log)

Log files should be saved with a file extension of ".log". Similar to command files, these are saved by making the log window active (basically, clicking in it anyplace) and clicking File -> Save in the menus.

Logs, like commands, are saved as simple text.

A log is the one form of output that all SAS processing creates. Unlike a lot of other statistical software, this echo of your commands, processing notes, and error messages is separate from your statistical results. When you are working interactively, these notes appear in the Log window and are being held in your computer's memory (a "buffer"), so they are not saved unless you save them manually. If the need arises, you can save the log to a file automatically by batch processing or by using the PROC PRINTTO command.

Results Tables (*.html, *.lst, *.rtf)

Statistical tables and graphs can be saved together or separately, and in several different formats. Saving your results is best done by adding the appropriate commands to your SAS program.

Common formats for results are HTML, simple text ("listing" or lst), Word document ("rtf" or rich text file), and Adobe (pdf). Many other formats are also possible.

By default, SAS produces results in HTML format in the Results Viewer window, combining tables and graphs into a single output document. However, this is lost when you end your SAS session. The options for saving your results manually are clunky at best. You will want to decide on a format for your output, and add the appropriate ODS commands before and after the code that produces what you want to save. More on the details, later.

Results Graphs (*.png, *.jpg)

It will be typical to save graphs as part of a results document, but they can also be saved separately, and in several different graphics formats. As with tables, this is most gracefully accomplished with ODS commands.

You can also right-click on a graph in the Results Viewer and save it manually. This gets tedious quickly.

SAS Files
SAS Files