270 likes | 314 Views
EPIB 698C Lecture 1. Instructor: Raul Cruz-Cano raulcruz@umd.edu. 1. Syllabus. What is SAS?. SAS = “ Statistical Analysis System ” – developed for both data manipulation and data analyses in 1976 Visit the SAS website: http://www.sas.com SAS vs Excel SAS is like a computer language. 3.
E N D
EPIB 698C Lecture 1 Instructor: Raul Cruz-Cano raulcruz@umd.edu 1
What is SAS? SAS = “Statistical Analysis System”– developed for both data manipulation and data analyses in 1976 Visit the SAS website: http://www.sas.com SAS vs Excel SAS is like a computer language 3
Basics of SAS 5 Windows EDITOR – file where you write code and comments for execution by SAS (save as .sas) LOG – file where notes about the execution of the program are written, as well as errors (save as .log) OUTPUT – file where results from the program are written (save as .lst) Explorer Window Results Window 4
Enhanced Editor Window Output Window Log Window Explorer Window Results Window Type SAS programs here. The "enhanced" editor has more advanced features than the traditional "program editor" used in SAS 6.12. View the results of SAS procedures including tables and line charts. Graphs will be displayed in a separate Graph window. View SAS programs as they execute including error messages and warnings. Browse your SAS tables (datasets) and libraries. Create new files and file shortcuts. Displays a hierarchical outline of SAS results to simplify output navigation. The SAS interface consists of multiple windows designed for specific functions. The following windows are open by default: 5
SAS Menus File: file input/output Edit: Editing contents in every window Contents in LOG and OUTPUT windows are not editable, but deletable View: view programs, log files, outputs, and data sets Tools: editors for graphics, report, table, etc Solutions: analysis without writing codes Window: navigating among windows Help: help information of SAS 6
SAS toolbar The toolbar gives you quick access to commands that are already accessible through the pull down menus Not all operating environments have a toolbar 7
SAS command bar Command bar is a place where you can type in SAS command. Most commands you can type in the command bar are accessible through the SAS menus or the toolbar 8
Controlling your windows The window pull-down menu Type the name of the window in the command bar Click on the window 9
Basic Rules of SAS Codes Every SAS statement ends with a semicolon ; Lines of data are NOT separated by semicolons SAS statements can extend over multiple lines provided you do not split a word of the statement across lines More than one statement can appear on a single line You can start statement anywhere within a line (not recommended) SAS is case insensitive, except for the values of categorical variables Words in SAS statement are separated by blanks 10
SAS Steps Two main types of SAS steps: Data Step: read in data, manipulate datasets etc. PROC Step: perform statistical analyses etc. DATA and PROC steps execute when a RUN, QUIT, or CARDS statement is enters Another DATA or PROC statement is entered The ENDSAS statement is entered 11
SAS Comments Two ways to comment: /* …..comments…..*/ good for long documentation good for commenting out sections of code *……comments……; good for commenting out one line of code only commented until first ‘;’ SAS Comments are green in (SAS steps are blue) 12
SAS Dataset Basic structure: a rectangular matrix Name Sex Age Observation 1 Jane F 30 Observation 2 Mary F 29 Observation 3 Mike M 28 Columns are variables Rows are observations
Example 1 /*Data instructor contains information of several teachers*/ data instructor; input name $ gender $ age; cards; Jane F 30 Mary F 29 Mike M 28 ; run; Proc means;var age;run; Part 1 of code
SAS data type (1) Numeric data: numbers Can be added and subtracted Can have decimal places Can be positive or negative (2) Character data: contains letters, numerals or special characters 15
SAS Dataset and variable names Dataset name Start with A-Z or underscore character _ Can contain only letters, numbers, or underscores Can contain upper- and lowercase letters choose names which are easy to be memorized Can be greater than 8 characters in SAS 8.0+ Variablename: same rule as dataset name
Examples: valid SAS names Parts LastName First_Name _Null1_ X12 X1Y1 17
Examples: invalid SAS names 3Parts Last Name First-Name _Null1$ Num% 18
Submitting a program in SAS First, get your program into the editor Type your program in the editor Open an existing SAS program: use open from the File full down menu or use the open icon or just click your SAS program directly 19
Submitting a program in SAS Make your editor window active, and submit your code by Submit Icon Enter submit in the command bar Select “submit” from the Run pull-down menu 20
Submitting a program in SAS Reading the SAS log window It starts with notes about the version of SAS and your SAS site number Original SAS code with line numbers added on the left Notes contains information about SAS data set and computer resources used 21
Assessing errors in .log file Non-error SAS messages begin with NOTE: SAS error message begin with ERROR: or possibly WARNING: In data set creation NOTE’s are important to read because they indicate if the data set was created correctly. Many times there are no errors yet the data set is not correct. ERROR message sometimes give you hints about options or keywords in DATA/PROC steps 22
The output window Viewing results from the output window You can save and print contents in the output window When you have a lot of output, one easy way to find the specific output is to use the list in the “results” window Part 2 of code 23
Creating HTML output Tools --- Options --Preferences Click on the “Results” tab Click the box next to “Create HTML” Once turned on, results will be show in the “Results Viewer” window Results viewer window just show one piece of output at a time To turn off, just uncheck it 24