SAS Non-Interactive Execution
SAS allows you to execute your job in non-interactive mode. For non-interactive execution, you must first create a command file with SAS statements. Let us take an annotated example, sample1.sas, to demonstrate it. (By the way, the file name is preferably ended with .SAS.) This sample1.sas uses the external data set called clas.dat.
Notice that the following SAS commands are typed in upper-case, whereas the comments are typed in normal mode and inside of /* and */. In the real world, SAS accepts both upper-case and lower-case, and ignores the comments in the process of execution.
TITLE 'COMPUTER ANXIETY IN MIDDLE SCHOOL CHILDREN';
/* The title should be enclosed in apostrophes as the above line. */
/* Up to 10 titles are allowed, e.g. TITLE1, TITLE2, ... etc. */
/* Also, semicolon (;) marks the end of each command line. */
DATA SAMPLE1;
/* DATA command marks the beginning of the DATA step and gives a name */
/* to the SAS data set(s) being created. */
INFILE 'clas.dat';
/* The INFILE command indicates the external file containing the
/* raw data. Using external data files usually makes the file
/* management easier in a middle- or large-size research project. */
INPUT ID 1-2 SEX $ 3 AGE 4 GRADE 5 EXP 6 COUNTY 7 C1 8 C2 9 C3 10 C4 11
C5 12 C6 13 C7 14 C8 15 C9 16 C10 17 M1 18 M2 19 M3 20 M4 21 M5 22
M6 23 M7 24 M8 25 M9 26 M10 27 MATHSCOR 28-29 COMPSCOR 30-31;
/* INPUT command describes your input by giving a name to each variable */
/* and identifying its location in the data record. It causes a data */
/* record to be read. Notice that SEX is a character variable with $ as its */
/* suffix, whereas the rest of the variables are numeric variables. */
COMPOPIN = C1 + C2 + C3 + C4 + C5 + C6 + C7 + C8 + C9 + C10;
MATHATTI = M1 + M2 + M3 + M4 + M5 + M6 + M7 + M8 + M9 + M10;
/* These two lines compute the sum of values across the argument lists */
/* for computer and mathematical attitude and save the results into */
/* COMPOPIN and MATHATTI for later use. */
LABEL ID='STUDENT IDENTIFICATION' SEX='STUDENT GENDER'
AGE='STUDENT AGE' GRADE='STUDENT GRADE'
EXP='YEARS OF COMP EXPERIENCE' COUNTY='COUNTY REPRESENTING'
C1='COMPUTER OPINION SURVEY' C6='COMPUTER OPINION SURVEY'
C2='COMPUTER OPINION SURVEY' C7='COMPUTER OPINION SURVEY'
C3='COMPUTER OPINION SURVEY C8='COMPUTER OPINION SURVEY'
C4='COMPUTER OPINION SURVEY' C9='COMPUTER OPINION SURVEY'
C5='COMPUTER OPINION SURVEY' C10='COMPUTER OPINION SURVEY'
M1='MATH ATTITUDE SCALE' M6='MATH ATTITUDE SCALE'
M2='MATH ATTITUDE SCALE' M7='MATH ATTITUDE SCALE'
M3='MATH ATTITUDE SCALE' M8='MATH ATTITUDE SCALE'
M4='MATH ATTITUDE SCALE' M9='MATH ATTITUDE SCALE'
M5='MATH ATTITUDE SCALE' M10='MATH ATTITUDE SCALE'
MATHSCOR='SCORE IN MATHEMATICS' COMPSCOR='SCORE IN COMPUTER SCIENCE'
COMPOPIN='TOTAL FOR COMP SURVEY' MATHATTI='TOTAL FOR MATH ATTI SCALE';
/* LABEL command supplies information that is used for labelling SAS display */
/* output so as to make it more descriptive. */
PROC PRINT DATA=SAMPLE1 LABEL;
VAR GRADE EXP MATHATTI;
/* PROC PRINT is the procedure called to print the values for variables. */
/* Without specification, PROC PRINT will print the values for all variables*/
/* The subcommand VAR specifies the selected variables. Since the LABEL */
/* command has been specified earlier, the system will print the labelled */
/* variables for the selected variables. */
PROC ANOVA;
CLASS GRADE;
MODEL MATHATTI=GRADE;
/* The procedure ANOVA produces a one-way analysis of variance. */
/* MATHATTI is the dependent variable and GRADE is the independent variable */
/* Any variables used as classification variables in the ANOVA procedure */
/* must be declared first in the CLASS statement to identify the groups for */
/* the analysis. The MODEL statement must come after CLASS statement. */
/* For the sake of simplicity, here we only calculate the relation between */
/* the MATHATTI and GRADE. */
PROC REG;
FIRST: MODEL MATHATTI=EXP;
PLOT MATHATTI*EXP;
/* The procedure REG is a general-purpose procedure for regression. It fits */
/* linear regression models by calculating the least-squares line. */
/* In this simple regression, we treat years of computing experience EXP as */
/* the independent variable and the math attitude MATHATTI as the dependent */
/* variable. FIRST: is the optional label. If you want to do multiple */
/* regression analyses, this option will let you easily locate the result of*/
/* any given regression analysis in your printout. The PLOT subcommand will*/
/* generate scatter plots. */
ENDSAS;
/* The ENDSAS; command terminates the current DATA or PROC step of an SAS */
/* session. Any commands following ENDSAS; are ignored in execution. */
From the previous annotated program, you should have an initial impression of some frequently used SAS commands. You may use any text editor to create the sample1.sas file on your own.
Running the job non-interactively
To run the job noninteractively, from any UNIX operating system, at the system prompt, type:
sas sample1.sas
Replace sasmple1.sas with your own filename. When the job is executed, two files will be stored in your default directory: sample1.log, and sample1.lis. If there are error/s in your input file, no .lis file may be generated.
When you run a non-interactive job, the terminal is not free for other computing tasks until the job is completed. If you want to use your terminal for computing activities while the job runs in the background, use the & command, sas in:
sas sample1.sas &
This will free your terminal for other computing tasks while the job runs in the back ground. Once the job is completed the .log and the .lis file will be stored in the default directory.



