BookmarkSubscribeRSS Feed
Jorge77
Calcite | Level 5

I'm using SAS 9.4.

I have to randomize 100 patients to 2 treatments A and B, considering 2 strata: stratum 1 with 2 levels (a and b) and stratum 2 with 3 levels (xy and z).  But these strata present different levels proportions. For example: a 48% and b 52% and x 75%, y 20% and z 5%.

How can I put in the attached program these percentages?. In the next code I considered same proportions for all levels of strata but I would like to consider these proportions. Could you be so kind to indicate me how to incorporate changes in order to consider the different proportions in the levels of the strata?

 

 

 

* Code (considering same proportions on the different levels):

 

proc plan seed= 12345678;

factors

strat1=2 ordered

strat2=3 ordered

blocks=9 ordered

bsize=2 ordered ;

treatments trt=2;

output out=rlist1;

run; 

quit;

 

data random;

length treatment $ 11 CG $ 11 mmse $ 11;

set rlist1;

If trt in (1) then treatment = 'A';

else if trt in (2) then treatment = 'B';

If strat1 =1 then mmse = 'a';

else if strat1 =2 then mmse = 'b';

If strat2 =1 then cg = 'x';

If strat2 =2 then cg = 'y';

If strat2 =3 then cg = 'z';

subjid = put(_n_, z3.);

run;

 

proc report data=random nowindows;

column mmse cg subjid treatment;

define CG / "Setting" style=[just=C cellwidth=15%];

define MMSE / "Setting" style=[just=C cellwidth=15%];

define subjid / "Subject ID" style=[just=C cellwidth=15%];

run;

 

Thank you in advance,

Jorge77

4 REPLIES 4
Reeza
Super User

Look at proc surveyselect with proportional sampling. 

Jorge77
Calcite | Level 5

Thank you very much Reeza for your advice.

Using proc survey select: example with 2 strata with 2 levels in stratum1 (a=48% and b=52%) and 2 levels in stratum2 (x=75% and y=25%). In data set B we would have for example treatment B and the rest of patients in data set A would be given treatment A. I Do you think following code is correct?

 


data A;
do n=1 to 100;
if n<=48 then stratum1='a';
else stratum1='b';
if (1 le n le 36) or (49 le n le 78) then stratum2='x';
else stratum2='y';
output;
end;
run;


proc sort data=A;
by stratum1 stratum2;
run;


proc surveyselect data=A method=srs n=(24 26) out=B;
strata stratum1;
run;


proc print noobs data=B;
run;

Jorge77
Calcite | Level 5

Dear Reeza,

I have modified the code:

 

data A;  
 do n=1 to 100;    
  if n<=48 then stratum1='a';    
  else stratum1='b'; 
  if (1 le n le 36) or (50 le n le 88) then stratum2='x';
  else stratum2='y';
  output;  
 end;
run; 
proc sort data=A;  
 by stratum1 stratum2;
run; 
proc surveyselect data=A method=srs rate=(0.48 0.52)  out=B;  
 strata stratum1;
run; 
 
proc sort data=A; by n;
proc sort data=B; by n;
data AB (keep=n stratum1 stratum2 treatment); merge A (in=a1) B (in=b1); by n;
 treatment='A';
 if a1 and b1 then treatment='B';
run;
 
proc freq data=AB;
tables treatment*stratum1;
tables treatment*stratum2;
run;
Jorge77
Calcite | Level 5

I would appreciate if some colleague could tell me if following code is correct. This is an example of using proc survey select with N= 100 individuals for assigning 2 treatments (A and B) but with 2 strata, with 2 levels in stratum1 (a=48% and b=52%) and 2 levels in stratum2 (x=75% and y=25%):

 

* I create the sample of N=100 with the 2 strata with different proportions of levels;

data A;  
 do n=1 to 100;    
  if n<=48 then stratum1='a';    
  else stratum1='b'; 
  if (1 le n le 36) or (50 le n le 88) then stratum2='x';
  else stratum2='y';
  output;  
 end;
run; 
proc sort data=A;  by stratum1 stratum2;
run; 
* In data set B we would have treatment B and the rest of patients in data set A would be given treatment A;
proc surveyselect data=A method=srs rate=(0.48 0.52)  out=B;  
 strata stratum1;
run; 
* Merging the 2 data sets;
proc sort data=A; by n;
proc sort data=B; by n;
data AB (keep=n stratum1 stratum2 treatment); merge A (in=a1) B (in=b1); by n;
 treatment='A';
 if a1 and b1 then treatment='B';
run;
 
Thank you in advance,
Jorge77

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 4 replies
  • 4444 views
  • 0 likes
  • 2 in conversation