Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc."— Presentation transcript:

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

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

3 Summer 2007 SAS Workshop3 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

4 Summer 2007 SAS Workshop4 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

5 Summer 2007 SAS Workshop5 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

6 Summer 2007 SAS Workshop6 What is the SAS System Really? SAS is a COMPUTER PROGRAM for managing and analyzing data It is a TOOL!

7 Summer 2007 SAS Workshop7 “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

8 Summer 2007 SAS Workshop8 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

9 Summer 2007 SAS Workshop9 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!

10 Summer 2007 SAS Workshop10 SAS Programs A SAS program is a sequence of statements executed in order Every SAS statement ends with a semicolon (;)!

11 Summer 2007 SAS Workshop11 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

12 Summer 2007 SAS Workshop12 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 (*/)

13 Summer 2007 SAS Workshop13 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…

14 Summer 2007 SAS Workshop14 SAS Example Program 1 Data FEV; *Create new data set called FEV; Input Id Age FEV Height Sex Smok_Stat; Cards; 23151112.5420062.000000 23401102.6080066.000010 23601112.3540062.000000 23651132.5990062.500001 23652101.4580057.000000 23901103.7950068.500010 24201112.4910059.000000 24251133.0600061.500000 24501102.5450065.000010 24543112.9930066.500010 24601103.3050065.000000 24642134.7560068.000011 24701113.7740067.000000 24741102.8550064.500010 24801112.9880070.000010 25041112.4980060.000010 25051143.1690064.000000 25501112.8870062.500010 25551132.7040061.000000 25901113.5150064.000000 ; RUN; PROC PRINT DATA = FEV; /*Prints the data in FEV*/ RUN;

15 Summer 2007 SAS Workshop15 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!

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

17 Summer 2007 SAS Workshop17 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)

18 Summer 2007 SAS Workshop18 Missing Data Missing character data are represented by blanks Missing numeric data are represented by a single period (.)

19 Summer 2007 SAS Workshop19 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

20 Summer 2007 SAS Workshop20 Don’t be afraid to type the wrong thing…Just give it a Try!

21 Summer 2007 SAS Workshop21 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.

22 Summer 2007 SAS Workshop22 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”.

23 Summer 2007 SAS Workshop23 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)

24 Summer 2007 SAS Workshop24 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?

25 Summer 2007 SAS Workshop25 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;

26 Summer 2007 SAS Workshop26 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.

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


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

Similar presentations


Ads by Google