I wrtote it in EG 4.3. - it's wordy but it works... DATA strat_people ; INPUT participant gender $1. ; CARDS ; 1 M 2 F 3 M 4 F 5 M 6 F 7 M 8 F 9 M 10 F 11 M 12 F 13 M 14 F 15 M 16 F 17 M 18 F 19 M 20 F 21 M 22 F 23 M 24 F 25 M 26 F 27 M 28 F 29 M 30 F 31 M ; /***************************/ /* Define the sample sizes */ /***************************/ %let k=10; %let k2=20; /***********************************************************/ /* There are 31 participants so we need to split out into */ /* 3 datasets of 10, 10 and 11 with a 50% male and 50% */ /* female into each table (except the last since it's odd) */ /***********************************************************/ %macro looptest; %do %until (&count = 10); /* GENERATE A RANDOM VECTOR */ data strat_people_1; SET strat_people; random=RANUNI(-1); count=1; run; /* SORT OBSERVATIONS BY THE RANDOM VECTOR */ proc sort DATA=strat_people_1; BY random; run; /* SELECT THE FIRST K OBSERVATIONS */ data controla controlb controlc; SET strat_people_1(drop=random); rollup_var=1; IF _N_ le &k then do; if gender='M' then male+1; else female+1; if male<=5 and female<=5 then output controla; end; ELSE IF _N_ gt &k and _N_ le &k2 then do; if gender='M' then male+1; else female+1; if male<=10 and female<=10 then output controlb; end; ELSE output controlc; run; proc sql; create table controla_1 as select rollup_var, sum(count) as total_participants from controla group by rollup_var; quit; data _null_; set controla_1; call symput('count',put(total_participants,3.)); run; %put "&count"; %end; %mend looptest; %looptest; %macro print(value); proc export data=&value.(keep=participant gender) outfile="C:\directories\output\Randomize_People.xls" dbms=excelcs replace; sheet="&value"; SERVER='rvwsascpt01'; PORT=9621; run; %mend print; %print(controla); %print(controlb); %print(controlc);
... View more