SAS

SAS has data steps and procedures. Data steps are used to input, split up, and combine datasets and to create new variables or transform old ones. Examples of procedures are proc print, proc reg (for regression), proc anova, proc means, etc. Procedures can generate datasets as output, for instance if you want to later use the regression coefficients, you tell proc reg to create an out dataset. It's a good idea to tell each procedure which dataset to use, since otherwise it will use the last one created. Note that each line ends with a semicolon. Procedures should be followed by the run; command.

SAS is currently installed only on one workstation, "hilbert". If you have logged into another machine, you can type ssh hilbert to start a session on hilbert.

Help Pages
Web-based help is available from sas.com.

Startup
Start by typing sas &. You will see a bunch of windows (6?) appear. Locate the one which says "Program Editor", make it bigger, and paste in the following text.
data tires;
   input hardness tensile abrsloss @@;
   datalines; 
45   162   372      83    161    97        55    233    206       88    119    64 
61   232   175      59    161    249       66    231    154       71    151    219
71   231   136      80    165    186       71    237    112       82    151    155
81   224    55      89    128    114       86    219     45       51    161    341
53   203   221      59    146    340       60    189    166       65    148    283
64   210   164      74    144    267       68    210    113       81    134    215
79   196    82      86    127    148       81    180     32       56    200    228
68   173   196      75    188    128   
;
proc reg data=tires;
   model abrsloss = hardness tensile;
run;
proc plot;
    plot hardness * abrsloss;
run;
Big data files are not included as part of a program, but are read in with an "infile" statement. To do the same analysis using infile, create the data file first with only three numbers on each line (see emacs session. Save it as "tires.dat". Then the following commands will read it in and do the regression in SAS. Type into Program Editor:
data tires;
   infile "tires.dat";        ** you may need the complete path here;
   input hardness tensile abrsloss;
proc reg data=tires;
   model abrsloss = hardness tensile;
run;
proc plot;
   plot hardness * abrsloss;
run;
To get output, you have to submit the job. You can submit by picking Submit on the Run menu of the Program Editor window or click on the running figure icon in the ToolBox window. Usually when I submit a job, I switch to the Log window and look for red type to catch any errors, then to the Output window to see the analysis, then back to the Program Editor to fix any errors. When correcting mistakes, I remove text in the Log and Output windows (otherwise it gets added on to the end of the current content). Then in the Program Editor window I click on Run menu and Recall Text to get back the last batch of commands. When editing, if you want to delete a line of code, go left into the line numbers and type "d" and enter. To insert a line after the current line, type "i enter" in the numbers. You can delete k lines or insert k lines by typing the d or i and the number (then return).

Another option is to have an emacs window open containing the SAS code. Modify the code in the window, then drag the mouse over it (using left mouse button) and click in the SAS Program Editor window (center mouse button) to insert the text. If the command file ends with the .sas extension, then emacs may put you into ESS (Emacs Speaks Statistics) which also allows you to submit jobs. For more details on running within emacs see Emacs Speaks Statistics, ESS.

Tip for clearing output and log windows:
Don't expect your program to work right the first time. I usually forget a ";" or have a typo, if not some larger problem, so I often choose "Recall last submitted", edit that file and re-run it. A problem is that the Log and Output windows do not clear unless you make them clear, so I include this line to clear them:

dm "out;clear;log;clear;";
It tells the display manager (dm) to go to output, clear that window, then to log, and clear that window. I also set page length and line length with these options:
options ls = 78 ps = 66;

Batch Mode

Suppose that you need to use SAS for a homework assignment, but you are at home and don't want to come in to campus. You can run SAS "the old way" in batch mode and read the log and output files from home. You will need: Then you can create a file of sas commands which we'll call myjob.sas and transfer it to your math account using winSCP. Also transfer a data file if it is needed. Then use putty to connect to gauss.math.montana.edu (it's the only machine which the rest of the world can find). On gauss type
ssh hilbert
sas BATCH myjob.sas
more myjob.log
(You will have to log in to hilbert after the ssh command.)
SAS will create a file myjob.log which contains a summary of what it did including errors it found, and one called myjob.lst of output. I use the more command to read thru the log file looking for errors. If there were any, then I fix the *.sas file locally, reload it up to gauss, and run sas again. When everything works, you can use winSCP to download the *.lst file containing all your output.

Version 9 of SAS software has very nice web-based help. Here are some links to specific procedures:


Information about unix and emacs.

Other Stat package demos for unix packages:


Back to MSU Math Department Home Page


Author: Jim Robison-Cox
Last Updated: Tuesday, 14-Jun-2011 16:52:23 MDT