We’ll begin our discussion of descriptive statistics in the categorical half of our flow chart.
Specifically, we’ll start by numerically describing categorical variables.
As a reminder, categorical variables are variables whose values fit into categories.
Some common examples in public health are: sex, race or ethnicity, and level of educational attainment.
Notice that there is no inherent numeric value to any of these categories.
Having said that, we can, and often will, assign a numeric value to each category using SAS.
The two most common numerical descriptions of categorical variables are probably the
frequency count (you will often hear this referred to as the n)
and the proportion or percentage.
The count is simply the number of observations, in this case people, which fall into each possible category.
The proportion is just the count divided by the total number of observations.
In this example 2 people out of 5 people are Asian.
Said another way 40% are Asian.
Now let’s go over how to calculate frequency counts and percentages using SAS.
Here you can see that we’re beginning this video using the same height and weight data that we used in the previous video.
Even before conducting descriptive analysis, you may often want to just look over your data.
So far we’ve only viewed our data by opening the data set in the view table window, and it’s worked just fine.
However, there are other, more versatile ways to view our data.
One of them is the PRINT procedure – PROC PRINT.
Now Let’s use PROC PRINT to add our first PROC step to our program.
So, here we’re telling SAS to run the procedure called PRINT,
and we want to run the procedure on the data set called height_and_weight.
Then, as with any DATA or PROC step, we end it with a RUN statement.
Pretty cool huh?
As you can see this procedure tells SAS to create a table, called a list report,
displaying the data set height_and_weight in the results viewer window.
So, what does this get you that just opening the data set in a view table window doesn’t?
Well, in this case, nothing.
But as I said there are more advanced uses for PROC PRINT.
For example, what if we only want the table to display the id and height for some reason.
The NOOBS I typed in the PROC statement here is called an option.
In this case it tells SAS not to print the observation number to the list report when it executes my PROC PRINT statement.
And how would you find that information for yourself?
Well, I suggest you start with Google like this.
OK, so let’s type SAS PROC PRINT
If we just click on the first result that pops up,
we’re taken to SAS’s online documentation.
Now this can be a little bit overwhelming at first, but I promise you that it will get easier with practice – assuming you actually practice.
Now, if you scroll down you’ll see the word “options” in bold type.
Here you can see all the different options available for PROC PRINT.
Below each option is a brief description of what the option does,
and various other fragments of information.
If you continue to scroll down…
You will see the NOOBS option.
And, the documentation tells you that this option suppresses the observation number in the output.
That sounds about right.
Throughout the semester you’ll be asked to complete tasks that will require you to use options not
specifically discussed in the instructional videos.
This is done intentionally.
Look how many options, and combinations of options, are available for PROC PRINT alone.
There’s just no way that I can teach you how to use all of them.
But, I can give you practice learning to use options and solve other programming problems on your own.
My advice is NOT to memorize all them this semester;
rather, just to slowly pick them up as you need them.
Back to the program.
As you may have guessed, VAR is short for variable.
By adding the VAR statement to my PROC step, I’m telling SAS that I only want to see the variables id and height in my list report.
And it worked. I should point out that we did not just delete sex and weight from our data set.
All we did was print a list report in the results viewer window that includes only the variables id and height.
Now that we’re able to easily view or data, let’s return to our original purpose in this demonstration –
calculating frequencies and proportions.
At this point, if I asked you for the frequency of males and females in this sample,
I suspect that few of you would have any trouble telling me that the frequency for each sex is 2.
Further, if I asked you what proportion of this sample is female, most of you would still be able to easily tell me 0.5, or 50%.
But, what if we had 10 observations, or 100 observations, or 1,000,000 observations?
You’d get sick of counting pretty quickly.
Fortunately you don’t have to.
Here is a DATA step creating a slightly larger data set with the same variables that we’ve been using.
Below the DATA step is a new PROC step that uses the aptly named FREQUENCY PROCEDURE – or PROC FREQ.
In this most basic form of the frequency procedure all we need to give SAS are the keywords PROC FREQ,
use the keyword DATA to tell SAS which data set we want to run the frequency procedure on,
and then end the PROC step with a RUN statement.
After submitting the program four tables appear in the Results Viewer Window – one table for each variable in the data set.
If we look at the first table we can see that 4 statistics are displayed by default:
Frequency,
Percent,
Cumulative Frequency,
and Cumulative Percent.
We can also see that the first column includes the name of the variable being analyzed,
and then each unique value for that particular variable.
In this case, the variable name is id, and there are 20 unique values for id.
The next column to the right give you the frequency, or number of times, each value occurs in the data set.
Now, you will probably never be interested in analyzing id numbers,
but you can already imagine how this may be useful for data checking.
For example, you could quickly check to make sure that no subject id number was ever duplicated.
The third column is the percent column, which just displays the frequency as a percent.
So, 5% of all id numbers are 001.
The fourth column is the cumulative frequency.
This is just the number of times, this or any previous value was observed in the data set.
And the last column shown by default is the cumulative percent, which is the cumulative frequency expressed as a percent.
Often we’re not really interested in the cumulative frequency or the cumulative percent.
However, there may be times when we are.
Can you think of a circumstance when we may be interested in the cumulative frequency?
We may be interested in the cumulative frequency when the values are ordered in some meaningful way, like with a likert scale.
Ok, but we’re really more interested in frequency statistics for variables like sex.
How can we tell SAS to only run a frequency report for the variable sex?
Unlike the VAR statement in the PRINT procedure, you use a TABLE statement in the FREQ procedure.
This difference will make more sense down the road.
For now, just memorize it.
This PROC step is identical to the one above, except that we add the table statement using the keyword TABLE.
To the right of the keyword TABLE is the name of the variable for which we want to see a frequency report.
Now we’re looking at a frequency report for just the variable sex.
Sex takes on 1 of 2 unique values in this data set: Female or Male.
You can quickly see that there are 12 females and 6 males in our data set,
and that females make up about 67% of all the people in this sample.
Now look at the cumulative frequency.
This indicates that 18 people have a value of male or female for the variable sex,
but we already know that we have 20 people in our data set.
Why is the cumulative frequency only 18?
The cumulative frequency is only 18 because two people are missing a value for the variable sex.
And SAS tells you that right here.
Ok, but if that’s the case then why is the cumulative percent 100?
The cumulative percent is 100 because 100% of people with a non-missing value for sex have a value of Female or Male.
By default SAS generally reports statistics for non-missing values only.
It’s important that you always keep that in mind.
For the FREQ procedure you can override this default with the missing option.
In this third, and final frequency procedure we add the MISSING option to the right of a forward slash in the table statement,
but before the semicolon.
This syntax of adding statement options after a forward slash is common in SAS.
And now you can see that 2 people, or 10% of the sample, are missing a value for sex.
You can also see that the percent for female changed from 66.67 to 60,
and the percent for male changed from 33.33 to 30,
reflecting the fact that SAS is now counting missing as a unique category in and of itself.
At this point I want to add that I sometimes use the missing option for data checking purposes.
However, you generally won’t use the missing option when actually estimating frequencies and percentages while conducting analyses.
Now you try calculating frequencies and percentages on your own.