1 / 44

Welcome to the Exciting World of !

Welcome to the Exciting World of !. Lessons to familiarize yourself with . Getting to Know SAS. SAS is a computer program used to analyze data. In this course you will learn how to write programs for your data sets, run these programs, and interpret the output they produce. Resources.

Download Presentation

Welcome to the Exciting World of !

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. Welcome to the Exciting World of ! Lessons to familiarize yourself with

  2. Getting to Know SAS SAS is a computer program used to analyze data. In this course you will learn how to write programs for your data sets, run these programs, and interpret the output they produce.

  3. Resources The tutorials that follow will help you learn how to use SAS for the various statistical analyses covered in this course. Other useful resources are: • SAS Official Tutorial (available in an open SAS window under Help/Getting Started with SAS Software) • The Little SAS Book: A Primer, 3rd ed., by L. Delwiche & S. Slaughter, (2003) SAS Institute

  4. Resources, cont. • Applied Statistics and SAS Programming Language, 4th ed., by R. Cody & J. Smith, (1997) Prentice-Hall Inc. • UCLA Academic Technology Services • South Dakota State SAS Tutorial • Numerous online resources are also available through search engines, like Google

  5. Let’s Get Started! Open your SAS program. If you do not have a shortcut to SAS on your desktop, you will most likely find SAS under Programs from your Start Menu. You may be asked if you would like to run the SAS tutorial. If you opt not to see this notice every time you open SAS, the tutorial can be reached at any time by clicking on Help/Getting Started with SAS Software.

  6. SAS Tutorial

  7. SAS Windows When you open SAS, you will see 5 main windows: • Editor • Log • Output • Explorer • Results You can easily navigate between windows by clicking on the tabs along the bottom of the SAS window. Clicking on a tab will make that window active. Try it!

  8. Editor Window The Editor Window is where you write the SAS programs. You can type your data sets directly into the Editor window, or you can import data from an outside source, such as Excel. You will see examples of SAS programs shortly.

  9. SAS Windows: Editor

  10. Log Window The log window displays messages such as notes, errors, and warnings about your programs. It is important to always check the log after you have submitted a program to SAS. NOTEs are simply comments about the programs. WARNINGs are sometimes of concern when running your programs. ERRORs will stop your program from running, and they provide important information about what needs to be fixed before you can continue with the analysis.

  11. SAS Windows: Log

  12. Output Window The Output window will display the results from your analyses as well as anything you explicitly tell SAS to print, such as a data set. The output window is currently empty, because we have not run any programs.

  13. SAS Windows: Output

  14. Explorer Window The Explorer window gives you access to all of your files and data sets. The current program and data sets you are working with are stored temporarily in a “Work” file, which can be accessed by clicking on the file cabinet icon “Libraries.” We will explore this in more depth later.

  15. SAS Windows: Editor

  16. Results Window The Results window systematically lists each section of your output, making it easy to search through your output. You can also use the results window to save or print selected portions of your output. Because we have not submitted any programs, our results section is currently empty.

  17. SAS Windows: Results

  18. SAS Programs Now that you are familiar with the general appearance of SAS windows, let’s get to the fun part: SAS programs! SAS programs consist of ordered statements, which tell SAS what you would like it to perform. The programming language may seem awkward at first, but after some practice you will become comfortable using it.

  19. Statements SAS programs are made up of statements. Each statement is like a command to SAS, and each statement ends with a semicolon (;). This tells SAS that one statement has ended and another will begin. The following is an example of a program containing three statements. The first line tells SAS to do a univariate analysis on the data set called “example.” It is only going to run this analysis on the variable “height.”

  20. Notice on the previous example that certain words were in blue. These are words that SAS considers “key words.” You will become familiar with these key words and the color-coding system in SAS. NOTE: SAS is NOT case sensitive. Some people type key words in CAPS for easier reading and organization, but it is not necessary. Feel free to find a system that works for you. Also, SAS does not require statements to be typed on separate lines. It is a common practice to give each statement its own line and to indent each statement after the first line of the program for better organization. Again, this is not necessary, but it generally makes your programs easier to read.

  21. Comments Comments are statements that are ignored by SAS. They are very useful when organizing your data, because they can provide titles or headings throughout your code. They are set apart by either an asterisk at the beginning of the comment and a semicolon at the end, or by /* at the beginning and */ at the end:

  22. Entering Data in SAS Before you can analyze data in SAS, you must first enter a data set to work with. This is done using a DATA step, which contains statements that do the following: • name your new data set • name each variable • tell SAS that you are inputting the data • input the values of the data. A semi-colon on the next line completes your data set.

  23. Data Sets A SAS data set consists of rows and columns. Each row represents an individual unit (such as a person, plant, country, etc.) on which data was collected. Each column represents a variable which contains information about that experimental unit (such as gender, age, height, education, income, race, blood pressure, etc.)

  24. Variable Names When inputting the variable names, put a $ after labels for categorical variables. This tells SAS that the variable is not quantitative. Variable names must start with a letter or underscore (_), and they can also contain numbers. Let’s try creating a simple data set!

  25. The following program creates a data set called “example1” with five variables: clinic, diastolic blood pressure at 6 months, systolic blood pressure at 6 months, diastolic blood pressure at baseline, and systolic blood pressure at baseline. The program also creates a sixth variable called increase, depending on whether diastolic pressure was higher after six months than at baseline. The output is given a title, and then variables clinic, sbpbl, sbp6, and increase are printed in the output.

  26. Type this program into SAS:

  27. Running a Program You can run this program in multiple ways. The simplest is by clicking on the icon of the running man at the top of your toolbar (you will see the word “Submit” if you put your cursor over this icon). You can also right-click anywhere on your Editor window and select “Submit All.” If you would like to submit only a portion of your code, highlight the portion you would like to run, then either click on the running man icon or right-click in the editor window and select “Submit selection.” NOTE: You must submit your data set before you can analyze it. If you try to analyze a data set that has not been submitted, SAS will not be able to run the program.

  28. Always Check Your Log! The first step after running a program is to check your log to make sure there are no warnings or error messages. If your program did not run, the log will give clues about why it had to stop. Take a look at your log.

  29. The previous log shows no errors, and that means we are ready to look at our output. (Notice, now that you have printed your data set, you have something in your Results section with the title you gave it.) If your program did not run, or if there are Error messages in your log, compare your code to the sample code. You may have forgotten something as simple as a semi-colon at the end of a statement. Make appropriate changes and run it again.

  30. Output After you created the data set, you also told SAS to perform the procedure (PROC) of printing certain variables from that data set. You should now see those variables in your output window. Take a look. Do you see them? Do you see the new variable, increase, you created? Notice the title you created at the top of the output.

  31. Try Another One! Now that you’ve seen the basic format of a data set, try entering the following data set into SAS and printing the variables in your output. In addition, create a variable called resid for residency, where resid = ‘Y’ if the student is from MN, and ‘N’ if the student is not from MN. Try inputting the data set in SAS, run the program, and compare your results to the answer. Also, give your output a title.

  32. Use these data for your data set (don’t forget to put a “$” after any categorical variables):

  33. Checklist Did your program run successfully? Did you: • Check your log • Remember a semi-colon after every statement • Put a semi-colon on the following line after your last row of data See the next slide for sample code.

  34. Sample Code for Data Set

  35. Output of Variables

  36. Now that you’ve seen the sample code, make any necessary adjustments to your code and re-run your program. The next section will show you how to save your code and output.

  37. Saving SAS Programs To save a SAS program, while in the Editor window, click on File, Save As…Choose a location to save your file and a name for it. It will automatically be saved as a .sas file. After closing SAS, if you open that file, SAS will automatically start and your code will be in the Editor window.

  38. Saving Code as a Text File Some of your homework assignments will require you to submit your SAS code. To do this, you will need to copy and paste your code into some type of text editor. Sometimes it is possible to simply copy and paste your code into Word; however this does not always work and it is not recommended. As an alternative, copy and paste your code into a simple text editor, like Notepad. From Notepad, recopy the text, then paste it into Word. You can then save your code as a Word document.

  39. Example of Using Notepad and Word

  40. Saving Output For your homework assignments you will also be asked to incorporate your output into write-ups on each problem. It is important to know how to save your output so that it can be used in a Word document. While in the output window, click on File, Save As…A window will pop-up. Change the file type from List to RTF. Create a name for your file and decide where to save it. Your output is now saved as a .rtf file, and it can be used in Word.

  41. Save Output as a .RTF File

  42. Now that you have seen the basic SAS set-up, you will learn how to use SAS for data analysis! We start with descriptive statistics, then move on to hypothesis testing.

More Related