BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Zaichik17
Calcite | Level 5

Hello, I need to use RANUNI(5) and PROC RANK to randomize 30 subjects to Stage 1 and then 30 to Stage 2, and then again randomize to treatment Y and treatment Z. I'm not sure how to get there to be 15 in each group. My code below produced 14 and 16  for stage 1, but overall it is randomized  equally for all 60 subjects.  This is a homework assignment and I need to use the code I have below.

 

*Specifically, they would like assistance in establishing a randomization scheme for
a randomized Phase II study of Treatments Y vs. Z in advanced prostate cancer patients.
The study will be done in two stages. Fifteen patients per treatment will be assigned
in Stage 1 and 15 per group in Stage 2. Produce a randomization list for them indicating
how the total of 60 patients will be randomized to one of the two arms (15 to each arm
for Stage 1, and 15 to each arm in Stage 2). The list should sorted by Stage, numbered
from 1 to 30 within each stage, and show the corresponding treatment assignment Y or Z.
Check that you have achieved a balance between the 2 treatments within each block (15 Ys and 15 Zs).

*Randomize 60 patients;
DATA random;
DO Subject = 1 to 60;
number = RANUNI(5);
IF Subject <=30 then stage = 1;
else stage = 2;
OUTPUT;
END;
RUN;

*Use Proc rank to create rank variable to rank the patients to treatment groups;
PROC RANK DATA = random OUT = ranked;
VAR number;
RANKS numrank;
RUN;

*Assign 15 patients to each treatment group;;
DATA ranked2;
SET ranked;
IF (numrank<=30) THEN Treatment = 'Y';
ELSE Treatment = 'Z';
run;

proc sort data=ranked2;
by Stage;
run;
proc print data = ranked2;
var Subject Stage treatment;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I think you want a BY STAGE; in PROC RANK.

 

PROC RANK DATA = random OUT = ranked;
by stage;
VAR number;
RANKS numrank;
RUN;

*Assign 15 patients to each treatment group;;
DATA ranked2;
SET ranked;
IF (numrank<=15) THEN Treatment = 'Y';
ELSE Treatment = 'Z';
run;

proc freq data=ranked2;
tables treatment*stage;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

I think you want a BY STAGE; in PROC RANK.

 

PROC RANK DATA = random OUT = ranked;
by stage;
VAR number;
RANKS numrank;
RUN;

*Assign 15 patients to each treatment group;;
DATA ranked2;
SET ranked;
IF (numrank<=15) THEN Treatment = 'Y';
ELSE Treatment = 'Z';
run;

proc freq data=ranked2;
tables treatment*stage;
run;
--
Paige Miller
Ksharp
Super User
/*Why not PROC PLAN ?*/
DATA random;
call streaminit(123);
DO Subject = 1 to 60;
number1 = RANUNI(5);
number2 = RANUNI(5);
OUTPUT;
END;
RUN;
PROC RANK DATA = random OUT = ranked(index=(numrank1)) groups=2;
VAR number1;
RANKS numrank1;
RUN;
PROC RANK DATA = ranked OUT = ranked2 groups=2;
by numrank1;
VAR number2;
RANKS numrank2;
RUN;


proc freq data=ranked2;
table numrank1*numrank2/list;
run;

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 507 views
  • 0 likes
  • 3 in conversation