SAS for Windows and Macintosh offer online help and point-and-click menus, though all operations can be accomplished by writing and submitting a SAS program, as outlined in this document. The language used in SAS DATA and PROC steps is virtually identical on all systems that run SAS, with minor adjustments necessary to accomodate the operating system under which SAS runs.
SAS is distributed in a Base package, with a number of optional modules. The more widely-used add-on modules (SAS/STAT, SAS/GRAPH, SAS/FSP) are described in separate sections later in this document. A list of all add-on modules and a brief description of each is shown below in this Introduction. SAS for Windows is distributed on CD-ROM. Instructions for installing the CD-ROM are included with the purchase of a Site License.
The major advantage of SAS is its ability to use data from a wide variety of sources, and to manipulate the data to suit nearly any analysis need a user might have. In addition to reading raw data, SAS can use or convert system files created by other statistical or database packages such as Excel, Access, and so forth. This is accomplished with SAS/ACCESS software, either using a Wizard or with more traditional SAS PROCedure programs, both of which are documented in the SAS manuals listed in References at the end of this document.
Anyone wishing to use SAS for a microcomputer must install the BASE package. The add-ons are optional.
SAS for the Macintosh runs on a 68K or Power Macintosh with 8MB (minimum) of RAM, Macintosh System 7.5 or better, and AppleScript (for Power Macintosh).
The Base product includes the standard descriptive statistics and data handling procedures, and will operate by itself once installed. Additional modules (called "add-ons") are included in the package as distributed by ITS, and may be installed immediately, or added at any time.
Sample programs are included with all versions of SAS, and can be used to illustrate the various PROCedures and other operations of SAS. The use of these sample programs is described later in this document.
To access the Technical Support Notes, go to
and enter some relevant search terms in the page's Search field.
If you consult the TS Notes and find you still need help, please feel free to contact the Consultants at the User Services office, LVL Lower Commons, 213.740.5555.P>
The standard operating mode for SAS on Microcomputers is the Display Manager System (DMS), a five-window display in which commands are entered (EDITOR Window), a report of the operations is seen (LOG Window) and the statistical or other results are viewed (OUTPUT Window). The LOG Window is on the top, and the EDITOR is at the bottom, with the OUTPUT Window behind the other two. At the left of these basic three windows are the RESULTS Window (a navigation tree for the OUTPUT Window) and the EXPLORER Window (with an icon for the SAS Libraries, among other things).
Older versions of SAS typically provided a command line at the top of each window. You can request a command line in the Editor of SAS for Windows by clicking Tools>Options>Preferences, then click the View tab and select the Command Line box. In SAS for Macintosh, click Globals, then Options, then Command Line. (To remove the command line in Windows or Macintosh, type 'COMMAND' on the Command Line, and it goes away.)
There are two basic steps in the SAS Language: the DATA step and the PROC step. Each of these steps is constructed using SAS statements, and each statement ends with a semicolon. PROC steps are relatively straightforward specifications of variables, models and other parameters necessary to describe a problem to the SAS System. It is not necessary to explain the PROCs further in this document, as the SAS documentation is quite clear and concise for the majority of PROCs. On the other hand, the DATA step can range from a very simple three-statement description of raw data, to extremely complex programs that perform nearly any data manipulation task a statistical user can imagine. As such, the SAS user's understanding of the SAS DATA step may benefit from the overview presented later in this section.
Unless purged by the user, the contents of the OUTPUT and LOG windows for any given session are saved in memory as they scroll up, and can be reviewed at any time the system is not "running" (i.e., working on a SAS operation or analysis). The contents of these windows, as well as the current contents of the EDITOR each can be saved to a DOS or Macintosh file and/or printed out from SAS.
In Windows or Macintosh, to see what the keys do, type
keys in the command line at the top of the screen
(the field with the check-mark at the left of it), or
at a Window command line, if you have one.
The Keys window will appear.
To close the keys window, click on the button at the top left,
or type end at a Command Line in the window.
It is possible to have a window enlarged to fill the entire
monitor screen.
This is done using the ZOOM function. In Windows or Macintosh,
this can be done by clicking a button on the upper right
of the window itself.
If you use the command-line, you can type the zoom
command to zoom up the window.
SAS also allows the use of a function key to accomplish the ZOOM,
as noted in the Keys window.
Statements typed into the EDITOR are submitted by
clicking Run, then Submit (or, in the
Macintosh, click Locals, then Submit),
or by typing submit on a Command Line,
or the appropriate function key
as shown in the Keys window.
Statements previously submitted can
be "recalled" for revision or re-submitting by clicking
Run, then Recall (or, in the Macintosh, click Locals, then Recall),
or by typing recall on a Command Line, or by
using the appropriate function key.
SAS allows the entry of commands in upper or lower case letters, or combinations. Since each statement ends with a semicolon, there are no restrictions regarding the placement of statements, except that they be in the proper sequence. In other words, the user can have multiple statements in each line, continue statements on a second line, or more, without punctuation, or use a separate line for each statement. (One exception to this freedom is that when data are entered "in stream" (see below for explanation and example), 1) the raw data must follow a "cards;" statement, 2) the beginning of each observation in the raw data should be a new line, and 3) the only semicolon that appears is after all the raw data, on a line by itself, in column 1.) Examples in this document use separate lines for each statement, with subordinate statements indented. This has been done for the sake of clarity only. SAS simply reads from semicolon to semicolon, ignoring added blanks, until the last statement is encountered.
As noted immediately above, SAS statements entered and edited in the EDITOR are submitted to the system for execution using the point-and-click button, SUBMIT command, or appropriate function key.
When this is done, the commands leave the EDITOR window and begin appearing, along with appropriate NOTEs and ERROR messages, in the LOG window. Each group of submitted lines is saved in temporary memory, and may be recalled, as noted above. This recall facility is not limited only to the last group of commands submitted; you may recall many groups of commands merely by clicking (or entering) recall again, and again, if you wish.
Note that information CLEARed from the LOG or OUTPUT windows is not always retrievable. The entire window is refreshed and emptied, with the exception that in the LOG window, the numbering of SAS statements will continue as if the previous statements were still present in the LOG.
The Output Delivery System (ODS) has added a great deal of flexibility to the look and structure of SAS output. Output can be generated in the traditional "listing" (text/ASCII) format, or you can choose to see your output formatted by HTML tags, as if it were on a Web page. The HTML version of output can be customized with special colors, fonts, highlighting and formatting to your specifications.
ODS also adds modularity to the structure of SAS output. The Results window to the left of the traditional Display Manager System (DMS) windows (Log, Editor and Output) provides a navigation tree with one icon for the output from each submitted PROC, and each icon can be broken down (by clicking on the icon) to the sub-segments involved with each PROC's output. Each segment of output can be located in the navigator without having to scroll up and down through a whole session's output, as in the past. Also, any segment of output can be deleted from the tree and from the output window, without deleting the whole window.
The Output Delivery System (ODS) is documented at the Help menu choice inside SAS. You can also find information on ODS at the SAS Web site:
www.sas.com/rnd/base/index-ods-resources.html
http://www.usc.edu/its/doc/statistics/sas/faq/v8/
SAS changed the structure of SAS data sets in Release 7, as compared with prior releases of the system. SAS data sets created in prior releases will be readable in Release 7 and higher, but those created in 7 and higher will not be usable in previous Releases. In other words, SAS data sets are upwardly, but not downwardly, compatible with respect to Release 7 and beyond.
If you have SAS data sets created prior to release 7, SAS can read most of them in later versions without special attention, but it may be to your advantage to convert your SAS data sets for use in Version 7 or later. It is possible in many cases to make conversions without using any SAS engines, since the default engine for new SAS data sets is the one appropriate for the most recent version, and SAS automatically uses the appropriate engine for any SAS data sets it needs to read. In SAS documentation, however, the engines are specified, so these examples will follow that style.
Some of the following steps are recommended, some required, in converting SAS data sets, and each step is so labeled.
sasdata, and you might
create a new directory called v8data to store
the new data sets.
UNIX example:
libname old v612 '~/sasdata';
libname new v8 '~/v8data';
proc copy in=old out=new;
libname old v612 'c:\sasdata';
libname new v8 'c:\v8data';
proc copy in=old out=new;
~/sasdata
(or c:\sasdata).
http://www.usc.edu/its/doc/statistics/sas/faq/v7problems/no604.shtml
The FILENAME statement allows the user to associate a "nickname" with the location and name of an external file to be used in SAS. SAS refers to this "nickname" as a FILEREF, or file reference. This is convenient especially when files are stored in complicated sub-directory structures and have involved filenames. Once the "nickname" is associated with the file, the user need only specify the nickname and SAS knows where to find the file.
The syntax of the FILENAME statement is:
filename fileref 'filespec';
where fileref is any name (8 characters or less, beginning with an alphabet letter) chosen by the user, and 'filespec' (with the single quotes) is a complete DOS or Macintosh file specification, including drive letter, colon, subdirectory path (if there is one), filename and extension, as appropriate. The word FILENAME is always entered as-is: in general, the first word of a SAS statement simply tells SAS what activity you want performed. For example, if you have a file containing raw data on a diskette in the B drive and the file is called AB9825.DAT, you might choose the "nickname" RAW1 and enter the following statement:
filename raw1 'b:ab9825.dat';
If you have a file containing some SAS statements you use often (or any SAS program for that matter), the file is on your fixed disk (C drive) in subdirectory \PERSONAL\SASPROGS and the file is called TRY4.PRG, you might choose a "nickname" PROG4 and enter the following statement:
filename prog4 'c:\personal\sasprogs\try4.prg';
It becomes obvious that the ease of using "raw1" or "prog4" whenever these files are needed instead of the more complicated file specifications makes the FILENAME statement very useful.
It is usually possible, in situations where a file is needed only rarely, to use the complete file specification without a FILENAME statement. Refer to the SAS Language Guide for instructions.
libname libref 'directory';
but LIBNAME is used to specify DOS locations (subdirectories) or Macintosh folders, rather than individual files. DOS locations consist minimally of a drive letter and colon, and may also have a subdirectory (pathname) specified. Macintosh folders can be on the Hard Drive or on a diskette or other device, and can exist within other folders.
The LIBNAME statement sets up a relationship between the LIBREF (which is a sort of "nickname") and the actual DOS location or Macintosh folder. In effect, the LIBREF (or "nickname") becomes the name of the SAS library where you store or retrieve permanently-saved SAS Data Sets.
The LIBNAME statement is different from the FILENAME statement, in that the only way a user may make use of permanent SAS system files (SAS data sets) is through the use of a LIBNAME statement. (FILENAME statements, you will recall, are optional, as raw data and other sas files usually may be specified within single quotes wherever they are needed without the use of fileref "nicknames".)
Permanent SAS data sets are saved into DOS or Macintosh files through the combination of having an "active" LIBREF (established by a LIBNAME statement submitted earlier in the current SAS session), and a two-level data set name on the data step the user wishes to save permanently. The first level of the two-level data set name matches the LIBREF, and the second level becomes the primary filename of the file in the DOS (sub)directory or Macintosh folder where it resides. (SAS always assigns the extension ".SD2" to SAS data sets in Version 6.10 and above, and ".SSD" in SAS-PC; these are acronyms for "SAS Data" or "SAS System Data", respectively.)
Let's say you have a subdirectory that you set up to store SAS system files (SAS data sets), and that it is called "c:\personal\sasdata". This directory, or a corresponding Macintosh folder, must exist before you try to use it. SAS will not create these library locations.
At the beginning of a SAS session (or any time before you begin the data step which is to be saved), you establish a LIBREF, or "nickname", to reference this directory; for example,
libname sysdta2 'c:\personal\sasdata';
data epsilon;
data sysdta2.epsilon;
To reuse an existing SAS data set, in a SET statement in a DATA step or a DATA= option in a PROC step, the format is the same as above:
libref.yourdatasetname
libname peace4u 'c:\personal\sasdata';
peace4u.epsilon
options youroptionchoice;
options linesize=68;
run;
It is also important for the user to know that data sets are temporary unless the user specifies that they be saved on disk (or diskette) for future use. As explained above (see "The LIBNAME Statement"), the "nickname" specified on the LIBNAME statement is the key to making a data set permanent. SAS calls this "nickname" a LIBREF. The nickname is appended to the beginning of the data set name, making it a two-level name, as in:
data hardisk.helptry1;
In this example, "hardisk" is an arbitrary name which is chosen by the user, the only condition being that it match the LIBREF (or "nickname") in the previously submitted LIBNAME statement. If the user specifies only a single-level name, as in:
data try1;
SAS will supply the first levelname "WORK.", and will refer to the user's data set as WORK.TRY1 in subsequent LOG reports. There is no need, however, for the user to use the "WORK." prefix, as SAS always assumes this when a single-level dataset name is encountered.
The concept of the SAS data set will be explained further, and is, of course, documented in detail in the SAS Manuals listed at the end of this document. For the beginner, then, the basic idea is that the data set which will result from any DATA step is named in the DATA statement -- for example, DATA HELPTEST; -- then all the statements necessary to "construct" that data set are listed in statements that come after the data set's name. Once named and constructed with valid SAS statements, a data set may be "called" simply by using its name.
Remember that the statements that follow the name of the DATA step contribute to the final content of that SAS data set. The format for in stream data entry is as follows.
data helptry1;
input var1 var2 var3 id;
cards;
76 54 55 001
98 65 23 002
88 67 12 003
87 34 65 004
. . . .
. . . . (more data here)
. . . .
78 42 81 099
;
run;These statements will create a data set called WORK.HELPTRY1 with 99 observations and four variables.
The user may specify a filename in single quotes, or use a fileref
("nickname") established in a previously submitted FILENAME statement.
Hence, the following two examples
(these are DOS examples, but Macintosh folders can
be used, also) accomplish the same operation:
|
| filename raw7 'a:testraw.dat';
data readraw; | *(then later in the program:);
infile 'a:testraw.dat'; | data readraw;
input testa testb sex id;| infile raw7;
run; | input testa testb sex id;
| run;
|
In either example, SAS reads the raw data from the diskette in the A drive and creates a SAS data set (temporary, to be purged at the end of the current session) called WORK.READRAW. It will contain four variables, and as many observations as there are valid data lines in the "testraw.dat" file.
|
libname perm 'c:\sasdata'; | filename raw7 'a:testraw.dat';
*(then later in the program:); | libname perm 'c:\sasdata';
data perm.readraw; | *(then later in the program:);
infile 'a:testraw.dat'; | data perm.readraw;
input testa testb sex id; | infile raw7;
run; | input testa testb sex id;
| run;
|
Either of these programs would produce a permanent data set called READRAW.SD2, which would be stored in the \SASDATA subdirectory.
This important (and difficult) concept is explained in more detail in the introduction to this section ("THE DATA STEP") and in a section before that dealing with "The LIBNAME Statement". For further detail, consult the SAS References, and/or make use of ITS consulting support.
For example, imagine that you wish to create a new variable by arithmetically combining two previous variables, a common operation when a single score (SUMAB) is needed from two separate tests (TESTA and TESTB). You have already read your raw data into a SAS data set called PERM.READRAW (see examples above). You now copy PERM.READRAW into a new DATA step to create a temporary SAS data set called WORK.NEWVAR9 (or just NEWVAR9; SAS will append the "WORK." level as necessary), and add the statements that create the new variable:
data newvar9;
set perm.readraw;
sumab=testa+testb;
run;
The resulting data set, WORK.NEWVAR9, will have the same number of observations as PERM.READRAW had, but will now contain five variables instead of four.
DATA MYTEST3;
will begin a DATA step that will create the SAS Data Set WORK.MYTEST3. You may always refer to it simply as MYTEST3.
You may also choose to make any SAS Data Set permanent by using a two-level name in the DATA statement. The first level given by you overrides the WORK. default that SAS would have provided, and also serves as a "nickname" (SAS calls it a LIBREF) for the location in which the permanent data set is to be stored. LIBREFs are also used to point to the location where previously- saved SAS Data Sets are kept. This association between the nickname (LIBREF) and the location in the UNIX subdirectory structure or Windows or Macintosh Folder structure is set up with a LIBNAME statement which must appear before the two-level data set name appears.
LIBNAME statements have the following syntax:
libname <libref> '<subdirectory or folder location>';
where you choose the information inside the angle brackets. For example,
libname mysave '~/user3/sasdata'; /<-- UNIX example **/
libname mysave 'd:\user3\sasdata'; /<-- Windows example **/
libname mysave 'HardDisk:User3:SASdata'; /<-- Macintosh example **/
makes "mysave" the nickname for the subdirectory /user3/sasdata. Then, when either of the following statements appears,
data mysave.datarun2; <--further data step statements-->
proc means data=mysave.datarun1;
SAS uses "mysave" to point to /user3/sasdata, where the data set "datarun2" will be written, and where "datarun1" will already be located.
put _all_;
but this is definitely not recommended. The result of this technique cannot easily be described; try it some time, and you'll see why it should be avoided.
Unlike most SAS DATA steps, the DATA step used to write out raw data usually does not need to create and keep a SAS Data Set, so typically people will use a DATA _NULL_; statement. SAS also needs to know what file to put the raw data into, and this is specified by the FILE statement.
Suppose you have a SAS Data Set called MYTRY, which you created at some point earlier in your session. (You can also use SAS Data Sets saved permanently from previous sessions or jobs, by using a LIBNAME statement and a two-level name in the SET statement.) MYTRY has 100 observations, and ten variables called:
ID SEX AGE RACE TEST1 TEST2 HEIGHT WEIGHT IQ INCOME
Now, you want to create an ASCII (raw) file containing only three of those variables. This is how your program might look (the FILE statement example is for the UNIX environment; modify the external-file specifications accordingly for use on Windows or Macintosh files):
data _null_; set mytry;
file '~/rawinfo.dat';
put id test1 income;
run;
This will create (or overwrite) a file called rawinfo.dat in the home directory, and the file will contain all the values for ID, TEST1 and INCOME, separated from the other values by a single space.
Sometimes you have variables whose values aren't always the same number of digits or characters. In that case, the program above would output the values, but they would not line up. If you want values to be put in specific columns, regardless of their length, add column pointers (@n) to the PUT statement, as in the following example (the FILE statement example is for the UNIX environment; modify the external-file specifications accordingly for use on Windows or Macintosh files):
data _null_; set mytry;
file '~/rawinfo.dat';
put @1 id @10 test1 @20 income;
run;
data _null_; set mytry;
file '~/rawinfo.dat';
put id--income;
run;
proc means;
will produce output including the mean, standard deviation, and other descriptive statistics of numeric variables in the data.
By default, most PROCs will perform their operations on all numeric variables in the SAS data set. To specify just certain variables, the VAR statement is usually used, as in this example:
proc means; var height weight;
This outputs statistics only for height and weight, no matter what other variables are in the data, thereby reducing output.
When a PROC statement is written after one or more DATA statements (whether the DATA statements created permanent or temporary data sets), by default it performs its operations on the most recently created SAS data set. If the user wishes to perform a procedure on a data set other than that most recently created, the DATA= option is used, as in,
proc print data=readraw;
SAS will go into temporary storage (assuming this data set was created during the current SAS session), retrieve WORK.READRAW, and print the information therein in the OUTPUT screen.
It is possible to begin a SAS session with a PROC step, even though no DATA sets have been created, assuming there exists a SAS data set which has been saved on the fixed disk or on diskette. The only requirement is to tell SAS where to find the data set (LIBNAME statement) before the beginning of the PROC step. Immediately after SAS is invoked and the Display Manager appears, the following statements might be entered:
libname today6 'c:\sasdata';
proc freq data=today6.readraw;
---[optionally, more SAS statements]---
run;
-work
For example, to direct SAS to use c:\tmp for its workspace,
change the configuration file (typically sasv9.cfg)
to look like one of the following:
-work c:\tmp
-work Hard_Drive:SASFolder:folder4work
To redirect workspace temporarily, invoke SAS from the Run or Start box and add some text like the example above, or go to the icon Properties box and add the text there.
If you have requested a command line in SAS for Windows or Macintosh, you can write the contents of any window to an external file by using a FILE command at the command line of the window you want to save, followed by a complete FILESPEC in single quotes. The format is,
COMMAND===> file 'd:\pathname\filename.ext'
where "d:" is the disk(ette) drive letter, and "\pathname" is the subdirectory specification, if any. In SAS for Macintosh, the pathname (if any) is the name of any folder(s) where the file is to be written. Following are two examples of such FILE commands. The first writes the contents of a window to a file called MONDAY9.LOG on a diskette in drive B. The second writes a file called MEANOUT to the \PERSONAL\PROGS\ subdirectory of the C drive.
COMMAND===> file 'b:monday9.log'
COMMAND===> file 'c:\personal\progs\meanout'
Note that the otherwise ubiquitous semicolon is not used on the command line.
When a file is written from the LOG or OUTPUT window, the entire contents of the LOG or OUTPUT is written to the specified file, not just what appears on the screen at the moment. When writing a file from the PROGRAM EDITOR window, however, only those lines currently in the EDITOR -- not the lines previously submitted -- are written out. If you want previously submitted lines to be written to the file, simply recall them (with the RECALL command at the command line or by using the F9 key) before issuing the FILE command.
The file written from the contents of any window is a DOS file which can be printed, listed and altered by any editor (including the SAS Program Editor) or word processing program. In Release 6.11 and later, however, you may need to change the character set SAS uses by default for the window display, as SAS now uses a high-ASCII set that doesn't translate well to some printers. If you suspect you need to simplify the character set, use the following OPTIONS statement before the PROC that generates the output:
OPTIONS FORMCHAR='|----|+|---+=|-/\<>*';
When a file is printed from the LOG or OUTPUT window, the entire contents of the LOG or OUTPUT is printed, not just what appears on the screen at the moment. When printing out lines from the PROGRAM EDITOR window, however, only those lines currently in the EDITOR -- not the lines previously submitted -- are printed. If you want previously submitted lines to be printed, simply recall them (with the RECALL function) before requesting the Printout.
In SAS for Windows click on File, then Open Program to bring the contents of an external file into the Program Editor. In SAS for Macintosh, click File>Open>Read File.
In SAS for Windows or Macintosh if you have requested a command line for the Program editor, you can use the INCLUDE command. For example, if you had your SAS commands stored in the \PERSONAL\PROGSAS subdirectory of the C: drive in a DOS file named TEST132.PRG, simply type on the PROGRAM EDITOR command line (not in the normal data-entry field):
COMMAND===> include 'c:\personal\progsas\test132.prg'
and hit return. The contents of the requested data set -- a pre-written SAS program -- will appear in the PROGRAM EDITOR and could then be submitted for execution or edited and submitted later.
This same INCLUDE process could be used, of course, for any editable file -- including files saved from the LOG or OUTPUT windows -- making the SAS Editor useful for tailoring SAS output for use in reports and other applications.
The "Import Wizard" and "Import Wizard" methods are probably the simplest method of doing these types of conversions. In Version 7 and later, PROC IMPORT and PROC EXPORT have been added to emulate the Import and Export Wizards.
For further documentation on PROC DBF and PROC DIF, as well as PROC IMPORT and PROC EXPORT, please see the SAS® OnlineDoc(tm) at:
http://www.usc.edu/its/doc/statistics/sas/
then choose the "SAS® OnlineDoc(tm)" link.
For further documentation on the more customized approach (referred to as 'the hard way' above), see SAS/ACCESS Interface to PC File Formats, listed at the end of this document (and available in some User Areas), as well as the above-mentioned OnlineDoc(tm).
proc dbf db5=tommy out=tomsas;
run;
To convert a SAS Data Set into a dBase file, run PROC DBF as in the following example. We assume here that we have a permanent SAS Data Set called "medical" in a directory called "C:\mysas", and that we want to create a dBase IV file called "medicine.dbf" to be stored on the diskette in the A: drive.
libname oldsas 'c:\mysas';
filename newdbf 'a:\medicine.dbf';
proc dbf db4=newdbf data=oldsas.medical;
run;
Traditionally SAS has been able to convert Lotus-created .DIF files into SAS data sets, but not all .DIF files are the same. More recent formats called .DIF (Data Interchange Format) and created by Excel or Microsoft Access may not work with PROC DIF. In these cases, the recommended workaround is to create a .DBF file or, if the correct Release of SAS is being used, create a .XLS file and use the "Import Wizard" (see above). When outputting a .DIF file from a SAS data set for use in spreadsheet (or other) software, it seems there are no problems like those found when trying to input .DIF to SAS. .DIF files created by SAS normally can be read in old Lotus or in new Microsoft Access and Excel versions. To convert a .DIF file to a SAS Data Set, run PROC DIF as in this example. (Running PROC DBF or PROC DIF under SAS for Windows requires that SAS/ACCESS software be installed.) We assume here that we have a .DIF file called "thomas.dif" in the current directory, and the SAS data set called "thomasas" will be temporary.
filename thom 'thomas.dif';
proc dif dif=thom out=thomasas;
run;
To convert a SAS Data Set into a .DIF file, run PROC DIF as in the following example. We assume here that we have a permanent SAS Data Set called "medinfo" in a directory called "C:\mysas", and that we want to create a .DIF file called "medinfo.dif" to be stored on the diskette in the A: drive.
libname oldsas 'c:\mysas';
filename newdif 'a:\medinfo.dif';
proc dif dif=newdif data=oldsas.medinfo;
run;
As you can see, PROC DIF works in the same way as the examples shown above for PROC DBF, although there are more choices you may need to make, including whether you want to specify a variable name prefix (the default is COLn, where "n" is the ordinal number in which the variable appears: COL1, COL2, etc.), whether you want to skip a row or rows at the beginning of the .DIF file, etc. The documentation noted above gives complete details.
Note that these examples use DOS file specifications. The same SAS statements will work in SAS for the Macintosh with Mac file specifications in place of the DOS examples.
To understand the process of converting a .DBF or .DIF file to a SAS Data Set (or a SAS View, if you wish), you should notice first that there are three major steps:
LIBNAME XYZSAS 'C:\';
PROC ACCESS;
RUN;
LIBREF NAME TYPE
Access Name: XYZSAS . DBFTEST1 . ACCESS
Click OK.
Path: C:\DBASE\TOCONVRT
___ XYZSAS DBFTEST1 ACCESS
Type CV (Create View) on the line to the left of the name.
This will bring up the View Descriptor Display Window, in which you
specify both the name for the View Descriptor, and the name for
the output SAS Data Set. Your window might look like this:
Descriptor: Library: OLD Member: DBFVIEW1 Type: VIEW
Output SAS Data Set: Library: OLD Member: DBF2SAS
Path: C:\DBASE\TOCONVRT.DBF
<variable listing, with Action fields, etc.>
When you have finished customizing this view (note that unlike the Access Descriptor where you deselect variables if you wish, no variables are selected here unless you type 'S' under 'Func'), click Locals>End, and you will return to the main ACCESS Window, and both your View Descriptor and your final SAS Data Set will be written (as shown in the SAS Log).
SAS provides two Point-and-Click environments for performing analysis using many of the PROCedures. These interfaces make it unnecessary in many cases to write SAS code at all, though using them correctly requires a full understanding of how SAS stores and retrieves data (SAS Data Sets, Libraries, etc.).
The Analyst Application is available with Version 6.12 and higher. In the UNIX environment, it requires an X-Windowing interface. The Analyst Application provides a very user-friendly and intuitive (for those familiar with statistics) point-and-click environment for analysis and graphing of data that have been stored previously in a SAS data set. Analyst does not provide an interface for importing data or reading raw data from flat files. Data must be imported or read in by other methods before using the Analyst Application.
The Analyst Application is documented in a SAS publication that is listed at the end of this document. For more information, including a link to the SAS WWWeb site that discusses Analyst, visit:
http://www.usc.edu/its/doc/statistics/sas/faq/analystapp.shtml
To invoke the Analyst Application click on
Solutions>Analysis>Analyst,
or type analyst at any command line.
After generating an analysis or graph using the Analyst Application,
you can go to the Program Editor and click (or type)
recall to see the program that SAS used (actual SAS
code) to perform the analysis you requested.
If you wish, you can then save the program to a file for later use.
Enterprise Guide is the newest point-and-click environment available for SAS. It performs analyses as well as data reading and data manipulation. (Note that this software is not available on the Macintosh.) Enterprise Guide is distributed with the ITS version of SAS for Windows, but must be installed separately. Once installed, it will appear in the Programs choice of the Windows Start menu, and if you choose, SAS will create an icon for your desktop. The online instructions and Help system in the Enterprise Guide make it self-explanatory, and it is fully documented in a SAS publication listed at the end of this document.
SAS/ASSIST is an older interface that is not quite as user-friendly as the Analyst Application or Enterprise Guide. It does have the ability to create SAS data sets from raw data, as well as do many of the analyses normally available from SAS PROCs, but with the other two more recent point-and-click choices available, it may never be necessary to use this older interface.
help at a Command Line.
To use batch processing, enter all appropriate SAS commands into a DOS or Macintosh file using any text editor (including the SAS Program Editor). Take care to insure that necessary libname and filename statements are present and accurate.
c:\saswin\sas -sysin c:\programs\program.sas
This will start SAS, read program.sas, and write the .log and .lst files in the c:\saswin directory.
(NOTE that the description of Batch Mode processing in the SAS Companion for the Microsoft Windows Environment, Chapter 1 in the section "Submitting Code in .SS2 or .SAS files" is incorrect. It states that by double-clicking on such files in Windows File Manager, SAS will run the files. What actually happens is that SAS is invoked, and the file appears in the Program Editor, ready to run. This is interactive, not batch, mode.)
To run SAS in Batch Mode in the Public User Rooms, you must specify the absolute path to the SAS executable. In this case, you must redirect the .log and .lst files, as these files would normally be written (by default) to the directory where SAS resides, and users don't have write access to that directory. To run Batch jobs in the User Areas, replace c:\saswin\sas in the above examples with L:\programs\stat\saswin\sas, and add (in any order):
-log c:\tmp
-print c:\tmp
L:\programs\stat\saswin\sas
-sysin c:\programs\program.sas
-log c:\tmp -print c:\tmp
SAS Institute has posted TS 648, a Technical Support document in PDF format that outlines several other methods of running Batch jobs under SAS for Windows.
support.sas.com/techsup/unotes/SN/004/004494.html
Actually, the sample programs are separate files, each of which is a pre-written SAS program designed to illustrate the operation of a particular PROC or other SAS feature. The programs may be copied one by one into the SAS Editor and used there, or they may be copied onto the hard disk and "called" from there. If they have been copied, for example into the "C:\SAS\SAMPLE" subdirectory, they can be browsed by clicking on your "My Computer" icon.
In SAS for Windows, the Sample Libraries are organized according to the product, under the subdirectory named for that product. For example, the GRAPH sample programs are in !SASROOT\GRAPH\SAMPLE, where !SASROOT is the base directory in which you installed SAS for Windows (for example, C:\SASWIN).
You execute sample library programs just as you would execute
any SAS code stored in an external file.
One easy way to do this is to click on
File, then Open.
If you have a Command Line,
you can use the include command to load the
program into the EDITOR window.
For example,
COMMAND===> include '\sas\sample\anova3.sas'
will bring one of the ANOVA sample programs (there are several) into the EDITOR. You then submit this program and view the results.
If you are using SAS in the Public User Areas (King Hall or Waite Phillips Hall) or in Leavey Library, the sample programs for SAS for Windows are in the subdirectory for the part of SAS they pertain to. For example, the GRAPH samples are in
L:\PROGRAMS\STAT\SASWIN\GRAPH\SAMPLE
To see the STAT samples, use the same path, but
substitute GRAPH with STAT.
You can go to these directories
(using the "My Computer" icon or the DOS cd
command) to view and choose
the sample program(s) you want.
If you use the DOS prompt,
to find the program(s) of interest to you, type "dir".
To run a particular sample program,
invoke SAS and click on File, then Open, then Read File, or use
the "include" command (as shown above) followed by the pathname
where you found these files.
For example, to run the sample file
called "glimmix.sas", bring it in through the File Menu, followed
by Open, then Read File; or type the following in the EDITOR window:
COMMAND===> include 'L:\programs\stat\saswin\stat\sample\glimmix.sas'
and then submit.
A more extensive library of SAS sample programs is found at the SAS WWWeb site:
support.sas.com/techsup/sample/sample_library.html
SAS formats have the form xxx.yyy, where xxx is the name and sometimes length of the format, and yyy is the number of digits after a decimal. If there are no digits after a decimal, the format name/length ends with the period. For example, the SAS format for dollar amounts in the millions might be DOLLAR12.2, which would allow 12 characters (including the decimal), with the last two being after a decimal point. ROMAN10. would output values in 10 'digits' as Roman Numerals. SSN11. outputs social security numbers, such as 123-45-6789.
SAS also allows the use of formats for character variables.
These formats are similar to numeric formats, except that the
format names always begin with the dollar sign ($).
SAS Language allows users to assign their own formats to values in their data. Usually, this involves users asking SAS to replace numbers in their data with some kind of labels. The most common example is the user request that SAS take '1's and '2's in a variable called SEX and format those values as the words 'female' and 'male' when they are displayed in output.
original data output using user-defined format
----------------------------------------------------
1 female
2 male
2 male
1 female
2 male
Both SAS formats and user-defined formats can be assigned to variables in PROCs (which makes them apply only for the output of that PROC) or in the SAS Data Set (which causes the format to be used every time the value is used). This is true of both SAS formats and user-defined formats. The use of SAS formats is automatic, as all the internal SAS formats are kept in a library that is always available in every SAS job or session. The use of user-defined formats is a little more tricky, as the formats first must be created, then they must be made available to the SAS job or session that uses them. Here is a brief scenario:
Temporary user-defined formats (that will exist for the life of the job or session only) are created with a simple PROC FORMAT, as in the following example.
proc format;
value sexfmt 1='female' 2='male';
This creates a user-defined format called SEXFMT. (note that a period is placed at the end of the format name in all situations except the original VALUE statement where it was created). The use of 'FMT' is not required. This format could have been called ABCXYZ. if desired.
The format then can be used in a DATA step
data readin; input id gender;
format gender sexfmt.;
cards;
001 2
002 2
003 1
004 2
005 1
;
The format also could be used instead in a PROC step
proc print data=readin;
format gender sexfmt.;
1 male
2 male
3 female
4 male
5 female
proc format;
value $gender 'F'='female' 'M'='male';
This creates a user-defined format called $GENDER. (note that a period is placed at the end of the format name in all situations except the original VALUE statement where it was created). The format then can be used in a DATA step
data chartest; input id gendchar $;
format gendchar $gender.;
cards;
001 M
002 M
003 F
004 M
005 F
;
proc print data=readin;
format gendchar $gender.;
SUGGESTION: Assign user-defined formats in SAS data steps only when you are familiar with the use of permanent format libraries, and you intend to have yours available in every session or job. Otherwise, assign formats in PROC steps only when necessary.
To store formats in a permanent library, include the LIBRARY= option in the PROC FORMAT statement. As mentioned above, this requires a prior LIBNAME statement, as shown in this example.
libname library '~/sasfmts'; /* example for UNIX */
libname library 'C:\sasfmts'; /* example for DOS/Win */
libname library 'Hard_Disk:SASformats'; /* example for Mac */
proc format library=library;
value sexfmt 1='female'
2='male';SAS creates (or updates) a file in ~/sasfmts (or C:\sasfmts, or Hard_Disk:SASfmts:) called formats.sct01, which is the formats catalog. This file should not be deleted or edited.
Then, in a future job in which the formats are to be used, include the LIBNAME statement again. You may then refer to the user-defined formats that are in your library without further ado.
libname library '~/sasfmts'; /* example for UNIX */
libname library 'C:\sasfmts'; /* example for DOS/Win */
libname library 'Hard_Disk:SASfmts'; /* example for Mac */
proc print data=readin;
format gender sexfmt.;
SAS will find the format in the format library, and the output will contain the formatted values for GENDER, in place of the original numeric values.
This section will give simple examples of two types of Macros: those that don't use macro variables, and those that do. The SAS Macro language and operation is documented fully in the Reference on macros shown at the end of this document.
Example 1: a simple macro
Say you are going to create ten different SAS data sets, each with the same variables but different data, and you want to print the same group of six variables after each data step completes. You can write the PROC PRINT and associated statements ten times, or you can write it once into a macro, then call the macro after each data step.
%macro print1;
proc print; var id height weight age iq birthyr;
run;
%mend print1;
data one; set master; if birthyr=1946;
%print1
data two; set master; if birthyr=1950;
%print1
data three; set master; if birthyr=1955;
%print1
(etc.)
Example 2: macros that use symbolic variables
Macros can be made even more flexible by the use of symbolic variables, which SAS calls "macro variables". In the example above, each DATA step has one value that changes, while the rest of the SAS language (including the macro %print1) stays the same. We can make that changing value (which is the value for BIRTHYR) into a macro variable, include the DATA step as well as the PROC PRINT in the macro itself, and then tell SAS which value of the macro variable to use each time it executes. The macro (symbolic) variable name is specified in parentheses after the name of the macro, then each time the macro is called the actual value to be used is specified.
%macro dataread(year);
data temp; set master; if birthyr=&year;
proc print; var id height weight age iq birthyr;
run;
%mend dataread;
%dataread(1946)
%dataread(1950)
%dataread(1955)
(etc.)
The appropriate SAS driver for terminal screen output is set up automatically when you launch SAS. Just invoke SAS/GIS or run the graphics PROC (e.g., PROC GPLOT, PROC GMAP, PROC GCHART, and so forth) and your graph will appear on the screen in full color.
To print a graph in one of our user rooms, the best method is to print directly from the Graph window by clicking File>Print. Make sure the printer you want appears in the Printer window near the top of the Print dialog box.
If you wish to print your graph on a non-USC printer
or for any reason you'd like to have your graph stored in
a file for later printing, the recommended method is to
use the File menu option and make a PostScript or BitMap file, and then
print that file on a laser printer. (For those who don't have
access to a laser printer, consult the SAS Companion for Windows
or for Macintosh, or run PROC GDEVICE to find a driver that will
work for your printer.)
To make a PostScript file from a SAS-generated graph, run the
graph program (e.g., PROC GCHART), and when the graph appears
on the screen, click File>Export.
You then choose the file type that corresponds best to
the printer you're going to use. In most cases,
you should choose the PostScript or
Encapsulated PostScript file type, then save the file as shown
in the dialog box, creating a
Mapping is available in SAS/GRAPH, with maps of many
countries in the world, as well as United States maps down to the county
level, provided with the package (and available in all user rooms where
SAS can be accessed).
(SAS/GIS also offers mapping capability when the user has access
to GIS-type [Geographical Information Systems] data.)
The SAS/GRAPH maps provided by SAS Institute
are actually SAS data sets, and are accessed
in programs by means of a LIBNAME statement.
Use some form of the following LIBNAME examples to point to the maps
when using SAS in
Public User Areas
or in Leavey Library information commons:
*.ps file.
(NOTE: SAS makes a PostScript-ready file for both the PostScript
and Encapsulated Post Script file type choices.)
If you do not have a PostScript capable printer, the most likely
candidate for your file type is a BitMap (
For more information on SAS/Graph and SAS/GIS in general, see the
related links at:libname maps 'L:\programs\stat\saswin\maps'; /* Windows example */
libname maps 'Applications2:SAS:maps:'; /* Macintosh example */
SAS/INSIGHT runs only under OpenWindows (X-Windows) or in the microcomputer versions (Windows and Macintosh), and is invoked by typing "insight" on the Program Editor command line, or by submitting the following program:
proc insight;
run;
The Statistics Consultant gives short demonstrations of SAS/INSIGHT in the regular SAS Under UNIX class offered upon request (213.740.5555).
A complete set of examples of most SAS transport scenarios that involve the systems supported at ITS is available in:
www.usc.edu/its/doc/statistics/sas/sastransport/
www.usc.edu/its/doc/statistics/sas/faq/
Current schedules for User Services Classes (also called "Hands-On Workshops") are listed on the Web at:
http://www.usc.edu/libraries/adventures/Any Statistics Software class can be taught when groups of five or more users request them. Other ITS Classes by special arrangement may require a minimum of 10 attendees. Classrooms must be arranged by those requesting the class. Contact the User Services office for details, or visit
www.usc.edu/its/doc/statistics/help/classes/requests.shtml
www.usc.edu/its/doc/statistics/sas/
As of Version 9 of SAS, full documentation for most parts of the SAS System can be accessed through the Help menu inside SAS. This documentation is installed automatically along with Base SAS.
Most of the "paper" (i.e., books) references are available in the manual racks in the Public User Area in the basement of Waite Phillips Hall. Some also are in the King Hall User Area manual racks and in the Leavey Library Information Commons (ground floor).
SAS® is a registered trademark of the SAS Institute, Inc., Cary, NC, USA.
Consulting. The ITS Consultants may be familiar with the language and general operations of this software, but it may be necessary to make an appointment with a member of the full time staff in order to receive detailed help. Support of statistics software is the responsibility of the ITS Statistics Consultant with the participation of other full-time ITS staff. These people may be contacted through the ITS Customer Support Center as shown here.
Customer Support. USC students, staff or faculty who would like information about ITS Workshops or about obtaining site-licensed software or other computing-related questions should visit the Customer Support Center in Leavey Library Lower Commons, or call 213.740.5555, or send eMail to <consult@usc.edu>
Documentation. This document, and many others on a variety of topics, are available in the ITS Customer Support Help System, available on the World Wide Web at:
http://www.usc.edu/its/
You can find Statistics Software Help Documents through the search engine at this same URL, or go directly to them at:
http://www.usc.edu/its/doc/statistics/help/
Newsgroups. Another source of information, this one providing the opportunity to exchange thoughts with other users, is the newsgroup 'usc.comp.all.stat.users'. For more information about reading news, subscribing to newsgroups, and related topics, visit
http://www.usc.edu/its/doc/internet/news/