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

PROC SORT and PROC UNIVARIATE - SAS Tutorial

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

Start my 1-month free trial

PROC SORT and PROC UNIVARIATE

- [Instructor] We just looked at our continuous table shell, and we know we will need a mean and standard deviation for SLEPTIM1. We will need those calculations for the whole sample for the first row of the table and we'll need them stratified by each level of all our categorical independent variables. Please open exercise file 315_SLEPTIM1 Estimates. You'll be happy because you get to use proc univariate, which you already know, but also learn a new proc, proc sort. Let's start with the proc univariate for SLEPTIM1 for the entire sample. We did this before, but now we are including it with our code, so when we look back at the code we used to fill in table one, we can find it again. Let's highlight and run. Looks great, we recognize these numbers. See the N? We'll put that on our Excel spreadsheet. We'll put this one in the magic blue box and also in the first row yellow box. And here our mean and standard deviation for the other yellow boxes. We'll do copy/paste in the next video. Let's go back to our code and generate the stratified numbers. Many SAS learners, at this point, would say okay, is there a way to add an option to proc univariate to stratify the results by levels of a categorical covariate? And if you ask that, the answer is yes, by using the by option. So once learning this, the SAS learner would typically then add this code to stratify results by diabetics, which is by DIABETE4, but look what happens when we run this code. Let's look at the output. Oof, this looks ugly. Remember that train wreck I talked about? Let's look at the log file. It says error, Data set R.ANALYTIC is not sorted in ascending sequence. The current BY group has DIABETE4 = 2, and the next BY group has DIABETE4 = 1. Once a student asked me, if they know it's not sorted, why don't they just sort it for you? Wouldn't that be a good idea? But those of you who really relish the old-fashioned programming where you have to think of everything in your code and very little is automated, you are the types who will love SAS. Let's go sort this dataset. See the next code? I start with a proc sort and the only command in it is by DIABETE4, then I immediately follow up with my proc univariate code before the next run statement. Remember, in an earlier video, where I bundled all those table commands together in a proc freq? You can do some of the bundling in your analysis. It doesn't work so well in your transformation code because the code executes all at once when it hits a run command, so, if you are editing data, it's hard to troubleshoot if you make a mistake. But in analysis, if you can keep it neat, this strategy works. Okay, now that we have a proc sort at the beginning of our code, let's highlight and run this and see the results. Much better, but we are at the end of our output. Where is the beginning? Let's use the Results pane to help. Let's expand our last univariate by clicking the plus in the Results pane. Okay, let's hit the plus for the first category, DIABETE4 = 1. As you can see, the next choice is to expand SLEPTIM1, that means you could, theoretically, put more vars in one proc univariate, but we only have one continuous variable, SLEPTIM1, so we cannot leverage this feature with what we're doing. Let's expand SLEPTIM1. See the top of the list, Moments? Double-click on Moments. And now we are at the top of our last output. See here, this is how you know what level these tables are about. These are the diabetics and these are the non-diabetics and here is the N, mean, and standard deviation for each level. As you can see, I put all the other stratification code here and you can run it if you want. But to be honest, I usually run the clusters of code one group at a time and then fill in the table shell as I go. Let's go put the numbers we just generated into our table shell now. We'll do that in next video.

Contents