From the course: SAS Essential Training: 1 Descriptive Analysis for Healthcare Research

PROC FREQ with options - SAS Tutorial

From the course: SAS Essential Training: 1 Descriptive Analysis for Healthcare Research

Start my 1-month free trial

PROC FREQ with options

- [Instructor] Let's start with two code files from your exercise files, 300_Categorical Tbl_All row and 305_One and Two Way Freqs. You'll see I have 300 open here. This file only has one PROC FREQ in it and that's the one-way PROC FREQ we need for the top all row. You are very familiar with this code by now. You'll see here that we are using the analytic data set and we are doing a one-way frequency on the variable ASTHMA3 with the missing option. Let's highlight and run this. Okay, you can immediately see the numbers that you would have to call out of this output and put in your table shell. You'd need the 5,577 as the total number with asthma in the data set and the 55,504 for the total number without asthma in the data set. Pretty straightforward. Even though this is a one-way frequency, it's not the only one-way frequency you will need. Remember how we have the all column before the has asthma and no asthma columns? That means for each variable you have on the rows, you will have to run a one-way PROC FREQ for the whole data set and also a two-way PROC FREQ for your stratified numbers. I put all that in the 305 code so let's go over to that file. Now two-way frequencies are not much different than one-way frequencies when it comes to PROC FREQ, but there is one important difference and that is the default output is way complicated in the two-way PROC FREQ. Just to demonstrate this, I decided to do a two-way PROC FREQ with the default output between our diabetes and asthma variable so you can understand how this output can make you crazy. Let's highlight and run. So here we are, enough numbers for you. Let's see if we can decode this. Here is our legend. In each cell, we have first at the top frequency. Then below that, the percent of the cell in the whole data set. Next we have row percent, then we have column percent. You probably have already noticed that because of the way I formatted the table shell, we only really need the frequency or the top number. I'll show you how to suppress the other numbers with options and at the same time put the output in a more user-friendly format. Let's go back to our code. Okay, so here we have our real PROC freqs. The first one is going to be for the diabetes row so I have two PROC FREQ table commands. The first for the one-way frequency for the all column. Notice the missing option in the semicolon at the end. And the second has our two-way frequency followed by two options, list and missing. List is the key. List will make it so the output does not drive you crazy. Let's highlight this and run this code and see how our output looks. Now here we go, much easier on the eyes. Here is our one-way frequency, looks familiar, and here is our two-way frequency. Let's look at the first row. This says that where DIABETE4 equals one and ASTHMA3 equals one, there is a total of 1,350 records in our data set. That means there are 1,350 respondents in our analytic data set who have both diabetes and asthma. The second row are people with diabetes but without asthma and the third is those with asthma and not diabetes and the last is the number of respondents without either condition. Having the two-way frequency output in this format makes it easier to call the results out of the output and place them in the right place on the Excel table shell. Okay, let's go back to our code. You might have noticed that I tried to keep the variables in the same order throughout the project. The data dictionary, the code we make to generate the variables, and also the order I put them on table one table shell. Following the table shell order, you will see I created a bunch of PROC freqs like I did for the DIABETE4 variable for all of the variables on the y-axis of our table. Generally, I don't run this whole file all at once. Instead, I run each piece of code then transfer the results to the Excel table shell, then I run the next piece of code. I'll show you how I do that in the next movie.

Contents