Sie sind auf Seite 1von 3


INSTRUCTIONS FOR USING SAS ON WINDOWS To begin, choose the "SAS System for Windows" under "Start" and "Programs" or on the desktop. SAS will begin to run, and an interface with three windows (Program Editor, Log, and Output) will appear. You can access any of the windows by clicking on the appropriate bar at the bottom, or by looking under the View menu. The Program Editor is where the SAS commands are typed. The Output window is where the results appear. The Log window is useful for finding errors in the SAS code. Once your SAS program is typed in the Program Editor window, you run the program. This is done by choosing "Submit" under the "Run" menu, or by pressing the F3 button. (If the SAS code in the Program Editor is erased upon running it, you can, after clicking in the Program Editor window, choose "Recall Last Submit" Under the "Run" Menu (or press F4).) When you run the program, the desired results should appear in the Output window. (If they don't, check the Log Window; there is probably an error.) If you run another program, the new results will continue to pile up in the Output window; the previous Output won't be automatically overwritten. This may get messy or confusing, so to clear the Output window at any time, you can click in the Output window and then choose "Clear All" under the "Edit" menu. You can save the program you've written by choosing the save option in the "File" menu. Having learned where to write the SAS code, how to run the programs, and where to look for the results, let's look at a sample SAS program. Note that when writing SAS code, you can include "comments", text that is not executed by SAS but is merely to help yourself or others understand what the code means. In SAS, lines which begin with an asterisk and end in a semicolon are comments. So are lines which begin with slash-asterisk and end with asterisk-slash. See the following program for examples:

/* begin SAS program */ * Whether you type lowercase or uppercase doesn't matter. ; * SAS is not case-sensitive. ; OPTIONS pagesize=50 linesize=64; * This OPTIONS line sets the margins for the Output. ; * You only need to do this line once, at the beginning of your program. ; DATA satscore; * * * * The DATA command names the data set ; The name should begin with a letter and be no more than 8 characters long ; I give this data set the name "satscore" b/c the data are SAT scores for states; Note that these data are on the CD-Rom that comes with the textbook;

INPUT state $ sat1990 sat2000; /* The INPUT command names the variables (the columns) in the data set */ /* These names should also be 8 characters or less */ /* The variable "state" has a dollar sign after it */ /* This is because it is qualitative (non-numerical) */ /* Any qualitative variable needs a dollar sign */ /* after its name in the INPUT line */ * When the data are typed/copied into the program, the command "cards" tells SAS ; * that the next lines consist of data. ;

1 of 3

11/26/2013 5:06 PM

* We could also use the command "lines" or "datalines" to do the same thing: ; cards; Alabama Alaska Arizona Arkansas California Colorado Connecticu Delaware D.C. Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachuse Michigan Minnesota Mississipp Missouri Montana Nebraska Nevada NHampshire NJersey NMexico NewYork NCarolina NDakota Ohio Oklahoma Oregon Pennsylvan RIsland SCarolina SDakota Tennessee Texas Utah Vermont Virginia Washington WestVA Wisconsin Wyoming ; 1079 1015 1041 1077 1002 1067 1002 1006 950 988 951 985 1066 1089 972 1172 1129 1089 1088 991 1008 1001 1063 1110 1090 1089 1082 1121 1022 1028 993 1100 985 948 1157 1048 1095 1024 987 986 942 1150 1102 979 1121 1000 997 1024 1034 1111 1072 1114 1034 1044 1117 1015 1071 1017 998 980 998 974 1007 1081 1154 999 1189 1154 1098 1120 1004 1016 1024 1126 1175 1111 1149 1089 1131 1027 1039 1011 1092 1000 988 1197 1072 1123 1054 995 1005 966 1175 1116 993 1139 1021 1009 1054 1037 1181 1090

/* A COMMENT ABOUT SEMICOLONS */ * Note that just about every line of code ends with a semicolon in SAS ; * The exceptions are the lines of data ; * but there IS a single semicolon at the end of all the data ; * Be careful that your semicolons are all there ; * This is a very common (and easily correctable) cause of errors in SAS ; * If your program has an error, first see if you've left off any semicolons;

2 of 3

11/26/2013 5:06 PM

/* How can we print these data into the Output Window? */ PROC PRINT DATA=satscore; TITLE "SAT Scores from 1990 and 2000 for the 50 States"; RUN; /* The TITLE command gives the Output a nice title */ /* The RUN command should appear at the end of this PRINT procedure */ /* or any other SAS procedure */ /* A missing RUN command is another common error -- be careful! */

/* end SAS program */

While you can print out the contents of the Output window directly from SAS, sometimes this is a waste of paper, since SAS isn't efficient in this way. A better way to print results is to first copy the Output from SAS and paste it into a word processing program such as Microsoft Word. (Use the "Courier New" font in Word if you do this.) Then print the Word document. You can also copy and paste into Word the graphs we obtain using PROC INSIGHT, as we will see on the first Homework set. This is the recommended way to print out graphs.

3 of 3

11/26/2013 5:06 PM