I have a continuous variable called SerumLvl and would like to create dummy variables using quartile numbers for the serum level so that I can compare its crude relationship with another categorical variable. I am really at a loss about how to do this.
Use PROC RANK with GROUPS = 4.
This will create a variable with 0, 1, 2, 3 based on quartiles.
If you have data with a lot of ties make sure to look at the options for dealing with ties.
The other option is to manually calculate the quartiles, merge in the information and use IF/THEN statements to create your variables.
@chrissiejade wrote:
I have a continuous variable called SerumLvl and would like to create dummy variables using quartile numbers for the serum level so that I can compare its crude relationship with another categorical variable. I am really at a loss about how to do this.
You'd be better off from a statistical point of view not creating the dummy variables, and using the continuous SermLvl values to compare it's relationship with another categorical variable. You could use Analysis of Variance to see if the means of SerumLVL differ by the categorical variable, or probably several other methods.
In fact, I would not believe the analysis done with dummy variables in this situation.
@chrissiejade wrote:
It's for a class where I am asked to do this so I don't really have another
choice unfortunately. I need to compare quartile information for serum
levels with a categorical measure of diabetes.
Well, that's a shame, that a class assignment is forcing you to perform a sub-optimal and weak analysis. Maybe you could strive for "extra credit" by doing it both ways, using the ranks, and then using the continuous SerumLvl values.
I also agree to use Proc Rank. See the example code below:
*Create a fake data;
***************************************************;
data dat1;
input SerumLvl 1-4;
datalines;
30.3
24.0
27.0
29.0
23.6
22.4
27.0
31.3
31.2
22.5
35.2
25.4
28.7
31.2
27.2
25.2
35.1
30.7
;
run;
*Use Proc Rank;
*Use groups=4 to get quartile numbers;
***************************************************;
proc rank data=dat1 out=out1 groups=4;
var SerumLvl;
ranks SerumLvl_qntl;
run;
proc print data=out1; run;
You can see the printout to be
Obs | SerumLvl | SerumLvl_qntl |
1 | 30.3 | 2 |
2 | 24.0 | 0 |
3 | 27.0 | 1 |
4 | 29.0 | 2 |
5 | 23.6 | 0 |
6 | 22.4 | 0 |
7 | 27.0 | 1 |
8 | 31.3 | 3 |
9 | 31.2 | 3 |
10 | 22.5 | 0 |
11 | 35.2 | 3 |
12 | 25.4 | 1 |
13 | 28.7 | 2 |
14 | 31.2 | 3 |
15 | 27.2 | 1 |
16 | 25.2 | 1 |
17 | 35.1 | 3 |
18 | 30.7 | 2 |
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.