An Introduction to Using SAS on PCs Dave Ribar 1 SAS is a system of software packages some of its basic functions and uses are database management inputting cleaning and manipulating data statistical analysis calculating simple statistics such as means variances correlations running standard routines such as regressions graphics producing two and three dimensional plots and charts producing maps statistical programming SAS allows you to program your own statistical routines 2 execution after logging onto PC invoke SAS from a desktop short cut from the start menu or from a class menu SAS will open five windows Program editor SAS commands are entered here you can create and submit a new set of commands or open edit and submit an existing file with commands Log this window describes the commands that have been run it also describes the resources that were used and the errors that were encountered while SAS processed your commands Output this window lists the statistical results or other program output if any from the commands output will only be generated if your program ran without errors Explorer this window helps you work directly with SAS files Results this window helps you work directly with different types of SAS output you can toggle between the different windows either by clicking each window s minimization and resize icons upper right corner of the window area clicking on the window itself or using the Window menu from the top menu bar operating sequence typically when you use SAS you will follow this sequence enter program commands by either typing the commands in the Program Editor or by opening an existing program sas file submitting the commands using either the submit icon on the tool bar or going to the menu bar and selecting Run Submit reviewing the Log window for errors reviewing results in the Output window when the commands come from or are stored in a file we refer to this sequence as a batch sequence you submit all of your commands in a batch instead of one at a time after the program has run if you want to keep a permanent copy of the material in any of the windows open click on the window go to the menu bar and select File Save or File Save As it s a good idea to keep copies of your programs data processing for statistical analysis usually involves many commands these will need to be repeated if you want to recreate or modify the data set saving a copy of the program keeps you from having to retype these commands each time you want to correct or modify your processing steps for final versions of analyses it s also good practice to save results from the Log and Output windows for documentation and record keeping purposes if you don t want to keep the material in a particular window open the window and at the menu bar select Edit Clear All after each program runs SAS appends the relevant information to the Log and Output windows if you are debugging or developing a program the Log and Output windows can get clogged with lots of results to leave the SAS system go to the menu bar and select File Exit 3 all SAS commands that are entered into the Program Editor share the same basic syntax note in the write up that follows terms marked in brackets represent things that you need to enter don t actually type the brackets regular command command note commands can extend across multiple lines the semi colon marks the end of the command nonexecutable comment comment OR comment commands in SAS are typically grouped into procedures or PROCs although some commands can be used anywhere in a program 4 commands that can be used anywhere in a SAS program FILENAME command FILENAME fileref Windows file name the FILENAME command assigns the internal identifier fileref to the specified Windows file this command is used in conjunction with reading or writing nonSAS data files i e text or ASCII files LIBNAME command LIBNAME internal name Windows directory SAS reads and writes SAS data files from libraries the LIBNAME command assigns the internal identifier internal name to the Windows directory where the SAS file is or will be stored OPTIONS command OPTIONS list of options the OPTIONS command resets SAS options such as the width of the program output LINESIZE the maximum number of observations to be processed OBS and whether SAS files should be compressed COMPRESS TITLE command TITLE title information the TITLE command causes title information to be printed at the top of each page of output this is a great way to document your output TITLE changes the information for the th title line RUN command RUN when you submit a set of commands to be executed SAS will execute all of the commands in every complete procedure one way to end a procedure is to invoke a new one another way is to put a RUN command at the end of the procedure placing a RUN command at the end of your program ensures that SAS will run all of the commands 5 DATA step this is a special type of procedure that is used to input manipulate and create data if data are input or read into a DATA step the observations are processes sequentially and the DATA step effectively loops over the observations DATA statement DATA sasdata the DATA statement is the first statement in a DATA step it creates a SAS data file called sasdata SET statement SET sasdata the SET statement inputs reads data from an existing SAS data file called sasdata INFILE statement INFILE fileref the INFILE statement is used to begin reading an external non SAS file fileref where fileref has been defined using the FILENAME command INFILE identifies the file to be read you can skip the FILENAME and fileref and simply type INFILE Windows file name INPUT statement INPUT variable1 variable2 the INPUT statement reads the data from the external file specified by the INFILE command into the variables variable1 variable2 etc as written this statement assumes that the INFILE data are all numeric with at least one blank space between the variables alternative formatting can be specified note for non SAS files you must use an INPUT statement and explicitly describe the data layout for SAS files this is handled automatically by the SET command OUTFILE statement OUTFILE fileref the OUTFILE statement is used to begin writing to an external non SAS file fileref where fileref has been defined using the FILENAME command OUTFILE identifies the file to be written to as with the INFILE you can skip the FILENAME and fileref and simply type OUTFILE Windows file name PUT statement PUT
View Full Document
Unlocking...