Hello, I wish to use a do until loop until the condition that there is a unique drug for each observation with some form of randomization for 3 repetitions is met. data units;
do Unit = 1 to 8;
output;
end;
run; The top shows dummy data. I will explain the overall problem that I have and how I'm trying to solve it. id Drug_1 Drug_2 Drug_3 1 2 4 3 2 1 2 4 3 3 1 2 4 4 1 2 5 4 3 1 6 2 3 1 7 1 4 3 8 3 2 4 In the second-fourth column, 1 shows up 2 times, 2 shows up 2 times, 3 shows up 2 times, and 4 shows up 2 times. They also do not repeat through each observation. In this example, the groups (1-4) are evenly distributed but I'd like to have the option to change their sizes depending on the condition To solve this, I am trying to cycle through different seeds to be able to get the desired outcome. To accomplish this, I created two local macros. n is to cycle through seed numbers and stop is to indicate when I've obtained the desired dataset. This outcome is shown through the sum of indicator being 0 or through drug 1 - drug 3 not equal to one another. %macro m(start);
%local n;
%let n=&start;
%local stop;
%let stop = 0;
%do %until(stop ne 0);
proc surveyselect data=units groups=(2,2,2,2) seed=&n reps=3 noprint
out=assignedUnits(rename=groupId=drug);
run;
proc sort data=assignedUnits;
by Unit;
run;
proc transpose data=assignedUnits out=wide1(drop=_NAME_ _LABEL_) prefix=drug_;
by Unit;
var drug;
run;
data desiredData;
set wide1;
indicator=.;
if drug_1 ne drug_2 and drug_1 ne drug_3 and drug_2 ne drug_3 then drug = 0;
else indicator=1;
st=.;
if drug_1 ne drug_2 and drug_1 ne drug_3 and drug_2 ne drug_3 then st = 0;
else %let stop=%eval(&stop+1);
run;
proc print data=desiredData;
sum indicator;
title "Seed number &n";
run;
%let n=%eval(&n+1);
%end;
%mend m; Unfortunately, the second if statement is not working. I want it to change the local variable stop to when the if statement is true but it has not been performing as desired. Is there any way to perform this?
... View more