BookmarkSubscribeRSS Feed
chrissiejade
Fluorite | Level 6

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. 

5 REPLIES 5
Reeza
Super User

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.

 

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
chrissiejade
Fluorite | Level 6
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.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
CiCi
Fluorite | Level 6

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 6174 views
  • 5 likes
  • 4 in conversation