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.
Lessons to familiarize yourself with
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.
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:
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.
When you open SAS, you will see 5 main windows:
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!
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.
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.
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.
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.
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.
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.
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.”
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.
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:
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:
A semi-colon on the next line completes your data set.
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.)
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!
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.
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.
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.
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.
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.
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.
Did your program run successfully?
See the next slide for sample code.
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.
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.
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.
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.
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.