1 / 27

SAS Workshop Lecture 1

SAS Workshop Lecture 1. Lecturer: Annie N. Simpson, MSc. Workshop Website. www.musc.edu/~simpsona/SASWorkshop/. Part I of Lecture 1. What is SAS? Why do we need it? How to open/manipulate the windows Where to get help Example 1…give it a try. SAS Introduction.

avedis
Download Presentation

SAS Workshop Lecture 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.

  2. Workshop Website www.musc.edu/~simpsona/SASWorkshop/ SAS Workshop

  3. Part I of Lecture 1 • What is SAS? • Why do we need it? • How to open/manipulate the windows • Where to get help • Example 1…give it a try SAS Workshop

  4. SAS Introduction • “SAS” = Statistical Analysis System, now it is not an acronym for anything • Developed in the early 1970s at North Carolina State University • Originally intended for management and analysis of agricultural field experiments • Now the most widely used statistical software SAS Workshop

  5. What is the SAS System? • The SAS System is an integrated system of software packages that enables you to perform: • Data entry, retrieval, and management • Report writing and graphics • Statistical and mathematical analysis • Business planning, forecasting, and decision support • Operations research and project management • Quality improvement • Applications development SAS Workshop

  6. What is the SAS System Really? SAS is a COMPUTER PROGRAM for managing and analyzing data It is a TOOL! SAS Workshop

  7. “I only want to know how to analyze data” With respect to statistical programs, most applied statistician/researchers spend most time doing data management (manipulation) activities in preparation for doing analysis Statistical Programming: 85% Data Manipulation 10% Comments 5% Analysis SAS Workshop

  8. SAS Help Resources Nothing replaces experience / trial and error • Me! • SAS Books by users (I have a shelf full) • SAS technical support on the web • Help files from the program SAS Workshop

  9. 3 Main Programming Windows • Program Editor – Enter, edit, and submit (run) SAS programs • Log – Displays messages about SAS session and programs that you submit • Output – View output from SAS programs that have been run *We will review these together in a moment! SAS Workshop

  10. SAS Programs • A SAS program is a sequence of statements executed in order • Every SAS statement ends with a semicolon (;)! SAS Workshop

  11. Two main parts to SAS code • DATA steps • read and modify data • Create new variables • create a SAS data set • PROC steps (or procedure step) • analyze data • produce results or output (e.g. – MEANS, FREQ, PRINT, CONTENTS) • A step ends with a RUN statement SAS Workshop

  12. Comments - The “Third” Step Comments are usually used to annotate the program, making it easier for someone to read your program and understand what you have done and why. There are two styles of comments that you can use: • one starts with an asterisk (*) and ends with a semicolon (;). • The other starts with a slash asterisk (/*) and ends with and asterisk slash (*/) SAS Workshop

  13. Lets open SAS together a take a look… • Open SAS • Review Window structure • Check out the help options • Practice with a small program… • Check out what errors look like… SAS Workshop

  14. SAS Example Program 1 Data FEV; *Create new data set called FEV; Input Id Age FEV Height Sex Smok_Stat; Cards; 23151 11 2.54200 62.0000 0 0 23401 10 2.60800 66.0000 1 0 23601 11 2.35400 62.0000 0 0 23651 13 2.59900 62.5000 0 1 23652 10 1.45800 57.0000 0 0 23901 10 3.79500 68.5000 1 0 24201 11 2.49100 59.0000 0 0 24251 13 3.06000 61.5000 0 0 24501 10 2.54500 65.0000 1 0 24543 11 2.99300 66.5000 1 0 24601 10 3.30500 65.0000 0 0 24642 13 4.75600 68.0000 1 1 24701 11 3.77400 67.0000 0 0 24741 10 2.85500 64.5000 1 0 24801 11 2.98800 70.0000 1 0 25041 11 2.49800 60.0000 1 0 25051 14 3.16900 64.0000 0 0 25501 11 2.88700 62.5000 1 0 25551 13 2.70400 61.0000 0 0 25901 11 3.51500 64.0000 0 0 ; RUN; PROC PRINT DATA = FEV; /*Prints the data in FEV*/ RUN; SAS Workshop

  15. Part II of Lecture 1 • Now that we know the basics lets talk about: • Some SAS rules of programming • Big data sets…don’t want to type those in! SAS Workshop

  16. Variables and Observations • Data consist of variables and observations (much like you are used to seeing in MSExcel spreadsheets) • Variables – columns • Observations - rows SAS Workshop

  17. Data Types • In SAS there are just two data types: numeric and character • Numeric fields are numbers • Character data are everything else • If it contains only numbers, then it may be numeric or character (example – zip codes) SAS Workshop

  18. Missing Data • Missing character data are represented by blanks • Missing numeric data are represented by a single period (.) SAS Workshop

  19. Rules for SAS names • Variable names must be 32 characters or fewer in length (used to be 8, some still like to stick to this shorter length) • Names must start with a letter or an underscore (_) • Names contain only letters, numerals, or underscores • Names can contain upper- and lowercase letters. SAS is insensitive to case SAS Workshop

  20. Don’t be afraid to type the wrong thing…Just give it a Try! SAS Workshop

  21. DATA step’s built in loop • DATA steps execute line by line and observation by observation • Must create variables before you use them • SAS takes the first observation and runs it all the way through the DATA step before looping back to pick up the second observation. In this way, SAS sees only one observation at a time. SAS Workshop

  22. Reading the SAS Log Every time you run a SAS job, READ the Log window first! Then go to the output window to view your result, that way you know that your results are “real”. SAS Workshop

  23. Things to remember • SAS does not automatically save any of the windows • You must save each window individually! Saving one, does not save any of the others. • Name each saved file the same for each related window. Ex: Program Editor – ‘zoo.sas’ (SAS Program File) Log Window – ‘zoo.log’ (SAS Log File) Output Window – ‘zoo.lst’ (SAS Output File) SAS Workshop

  24. SAS Data Sets • Before SAS can read your data, it must be in a special form called a SAS data set. • What type of data did we just use in our first example? • How do you expect your data to normally be stored? SAS Workshop

  25. LIBNAME Statement (i.e. SAS asks “Where are my SAS data sets stored?” • Use this statement to define your SAS Library location before using your SAS data sets • Follows your file storage directory structure Example: LIBNAME ABC ‘C:\DATA’; Proc Means Data = ABC.EX4A; Run; SAS Workshop

  26. Lets take a look at SAS to check it out… • Look for SAS data sets inside your C:\DATA file folder • Can you write a Libname statement so that SAS can “see” those same files • Rule #1: Only works if the data is a SAS Data Set…not Excel, or ACCESS, etc. SAS Workshop

  27. SAS Example Program 2 Open SAS, type and run the following program: Libname annie 'c:\DATA'; DATA new; Set annie.HTWT; Run; PROCCONTENTS DATA = new; TITLE "What is contained in the HTWT Data Set"; RUN; PROCPrint DATA = new; TITLE "Printing my HTWT data set"; RUN; SAS Workshop

More Related