SAS Interactive Execution
SAS allows you to execute your job either in non-interactive mode or interactive mode. To do an interactive execution, you must first enter the SAS system. The external data set is called clas.dat. In this interactive sample, we will:
- List the data for grade, years of computing experience, and total for math attitude scale;
- Do a one-way analysis of variance with grade as the independent variable and math attitude as the dependent variable; and
- Do a simple regression with years computing experience as the independent variable and the math attitude as the dependent variable.
Now, Let's have a quick look at the external data set, clas.dat. You may find that the data means nothing to you unless it has proper explanation. (The original clas.dat has 50 cases. For the sake of simplicity, here only 12 cases are listed. In your own SAS external data set, it is recommended that you have such fixed column input format.) Notice that line 8 has blanks, meaning a "missing value" in SAS system.
01F1111115155222521412344423028 02F1111212155125521522244422825 03F2111124254214445155511144531 04F2121442322232245155511244243 05F1121541221241244145412154844 06F1122124254224544145412155040 07F2122224144225555155511244033 08F2222 244224421412234422932 09F2222115155115421412244412524 10F2222114155124544154511159925 11F3213124154124545145511254634 12F3213115154225521422242154630
To enter into the SAS system, at the system prompt, you type:
sas -nodms
A site license information followed by a 1? prompt shall appear on the screen. You type in command or subcommand for each prompt followed by $lt;enter> key. 1 is the line number before the ? prompt. The line number will increase automatically as you enter lines of command or subcommand.
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.
1? 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. */ 2? DATA SAMPLE2; /* DATA command marks the beginning of the DATA step and gives a name */ /* to the SAS data set(s) being created. SAMPLE2 is an arbitrary name.*/ 3? 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. */ 4? INPUT ID 1-2 SEX $ 3 AGE 4 GRADE 5 EXP 6 COUNTY 7 C1 8 C2 9 C3 10 C4 11 5? C5 12 C6 13 C7 14 C8 15 C9 16 C10 17 M1 18 M2 19 M3 20 M4 21 M5 22 6? M6 23 M7 24 M8 25 M9 26 M10 27 MATHSCOR 28-29 COMPSCOR 30-31; 7? RUN; /* 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. */ /* RUN tells the system to execute the preceding group of SAS statements. */ /* For the sake of simplicity, the result of RUN command is skipped. */ /* The indentation is not required in the listing of the inputs. */ 8? COMPOPIN = C1 + C2 + C3 + C4 + C5 + C6 + C7 + C8 + C9 + C10; 9? 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. */ 10? LABEL ID='STUDENT IDENTIFICATION' SEX='STUDENT GENDER' 11? AGE='STUDENT AGE' GRADE='STUDENT GRADE' 12? EXP='YEARS OF COMP EXPERIENCE' COUNTY='COUNTY REPRESENTING' 13? C1='COMPUTER OPINION SURVEY' C6='COMPUTER OPINION SURVEY' 14? C2='COMPUTER OPINION SURVEY' C7='COMPUTER OPINION SURVEY' 15? C3='COMPUTER OPINION SURVEY C8='COMPUTER OPINION SURVEY' 16? C4='COMPUTER OPINION SURVEY' C9='COMPUTER OPINION SURVEY' 17? C5='COMPUTER OPINION SURVEY' C10='COMPUTER OPINION SURVEY' 18? M1='MATH ATTITUDE SCALE' M6='MATH ATTITUDE SCALE' 19? M2='MATH ATTITUDE SCALE' M7='MATH ATTITUDE SCALE' 20? M3='MATH ATTITUDE SCALE' M8='MATH ATTITUDE SCALE' 21? M4='MATH ATTITUDE SCALE' M9='MATH ATTITUDE SCALE' 22? M5='MATH ATTITUDE SCALE' M10='MATH ATTITUDE SCALE' 23? MATHSCOR='SCORE IN MATHEMATICS' COMPSCOR='SCORE IN COMPUTER SCIENCE' 24? 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. The indentation is not required.*/ 25? PROC PRINT DATA=SAMPLE2 LABEL; 26? VAR GRADE EXP MATHATTI; 27? RUN; /* 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. RUN will execute above statements */ /* For the sake of simplicity, the result of RUN is skipped. */ 28? PROC ANOVA; 29? CLASS GRADE; 30? MODEL MATHATTI=GRADE; 31? RUN; /* 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. For the sake of simplicity, the result of RUN */ /* is skipped. */ 32? PROC REG; 33? FIRST: MODEL MATHATTI=EXP; 34? PLOT MATHATTI*EXP; 35? RUN; /* 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. For the sake of simplicity, the result of RUN */ /* is skipped. */ 36? ENDSAS; /* The ENDSAS; command terminates the current DATA or PROC step of an SAS */ /* session. Any commands following ENDSAS; are ignored in execution. */
All the work done during an interactive session will be lost unless you save it. To save both the .log, and the .lis file, invoke SAS with the following parameter:
sas -nodms -print clas.lis -log clas.log
Once the SAS prompt appears, enter your SAS commands. The commands you enter will be stored in the .log file, and the output will be stored in the .lis file
To save the commands you entered during the SAS session, before exiting SAS session, at the SAS prompt, type:
52? filename mylog 'program.log'; 53? proc printto log=mylog; 54? run;
Note that the number at the beginning of each of the above lines (e.g., 52?, 53?, 54?) are SAS prompts. Do not type this. Once the command is executed the file, program.log will contain all the lines you typed in during the session. You could edit the file and resubmit the lines during another session.



