BookmarkSubscribeRSS Feed
saza
Quartz | Level 8

I was asked to make a 5 categorical variable and was able to find another forum that answered questions about making one, however, am having trouble applying it to my code. The first question is the following:

1) 

 Use the UNIVARIATE procedure to find the quintile (5-level) cut-points for the variable WEIGHT.
Using these cut-points, create a 5-level categorical variable called WTQUINT in a dataset called
MOD4_1 created using the TEMP6 dataset we left off with earlier. Run a FREQ procedure on this
variable.;

The following is my code that I thought was ok:

PROC UNIVARIATE DATA=temp6;
VAR WEIGHT;
RUN;

DATA MOD4_1;
SET Temp6;
IF 0 < WEIGHT <= 135 THEN WTQUINT=0;
IF WEIGHT > 135 THEN WTQUINT=1;
RUN;

PROC FREQ;
TABLES WTQUINT;
RUN;

PROC UNIVARIATE DATA=MOD4_1;
VAR WEIGHT;
OUTPUT OUT=CUTPTS PCTLPTS= .20 .40 .60 .80 PCTLPRE = P_;
RUN;

PROC PRINT DATA= CUTPTS;
RUN;

 The second question is the following: 

*2. Use the RANK procedure to create a 5-level categorical variable called WTQUINT2 in a dataset called
MOD4_2 from the dataset MOD4_1.

How do I create a ranking system if my obs values are 94, 94, 95, 95? I'm guessing I messed up when making my 5 categorical variable. I took 1/5, 2/5, 3/5, 4/5 out of 100% to get .20, .40. .60, .80 in my code. 

13 REPLIES 13
StatDave
SAS Super FREQ

Use the GROUPS=x option in PROC RANK to create a variable with x levels based on percentiles. 

saza
Quartz | Level 8
PROC RANK DATA=mod4_2 OUT=TWO GROUPS=X;
VAR WEIGHT;
RANKS WTQUINT2;
RUN;

this?
PaigeMiller
Diamond | Level 26

Well no, you don't use X, you use the actual number of groups (or levels) you want.

--
Paige Miller
StatDave
SAS Super FREQ
Specify GROUPS=5
saza
Quartz | Level 8

Yes I can see that. I guess what I should clarify is that i'm getting blank results when I use the code:
PROC RANK DATA=mod4_2 OUT=TWO GROUPS=5;
VAR WEIGHT;
RANKS WTQUINT2;
RUN;

Because my obs values from the first part of the question is
P_0_2= 94
P_0_4= 94
P_0_6=95
P_0_8=95

So my ranking isnt working.

 

Because I had to do the following before ranking:

 

DATA MOD4_2;
SET MOD4_1;
IF WEIGHT > 0 AND WEIGHT <= 94 THEN WTQUINT2=0;
IF WEIGHT > 94 AND WEIGHT <= 95 THEN WTQUINT2=1;
RUN;
StatDave
SAS Super FREQ
It doesn't produce printed output. Look at the contents of the created data set - TWO
saza
Quartz | Level 8
So,
PROC RANK DATA=mod4_2 OUT=FOUR GROUPS=5;
VAR WEIGHT;
RANKS WTQUINT2;
RUN;
PROC FREQ DATA=mod4_2;
TABLES WTQUINT2;
RUN;

I still get a blank table
StatDave
SAS Super FREQ
Look at the OUT= data set NOT the input data set (mod4_2)
proc freq data=four;
saza
Quartz | Level 8
Sorry, as you can tell I'm very new to SAS.

So Proc Freq data=four; where do I place that in my code?
StatDave
SAS Super FREQ
anywhere after the input data set (mod4_2) is created.
saza
Quartz | Level 8
Wish I could post an image of my blank table. I believe it is how I did my > and < steps prior. But your code is working.
Tom
Super User Tom
Super User

I think they are asking you to use PROC RANK on your original dataset.

So no need for you to manually try to create the 5 categories, let PROC RANK do that for you.

saza
Quartz | Level 8
No I figured it out. It was because I put a . infront of .20 instead of just 20 bc sas is already reading it as .20

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 13 replies
  • 2251 views
  • 4 likes
  • 4 in conversation