HI,
thank you very much for all the replies.
I attach the input dataset where the group variable , the strata variable and the ideintifier of the unit to be selected are respectively
ID1,str, ID2
and the allocation dataset that set for, each group, the number of units desired, n.
I have found a possible solution (accepting a minimum number of units in each strata equal to 1):
the problem could be solved more easily by allocating a unit in each strata and then the remaining units proportionally to the population, but I prefer a solution with surveyselect since I might possible change the allocation method.
In the following there is my code. Any suggestions for improvements and issues is welcome.
Moreover I would appreciate a solution using proc optmodel in order to start learning it and use for other problems.
thank you in advance.
%macro alloc(id,n);
proc surveyselect data=input n=&n out=samplegroup; where id1=&id; strata str/ alloc=prop nosample allocmin=1; run;
%if %sysfunc(exist(samplesizes)) %then %do; %if %sysfunc(exist(samplegroup)) %then %do; data samplesizes; set samplesizes samplegroup; run; %end; %end; %else %do; %if %sysfunc(exist(samplegroup)) %then %do; data samplesizes;; set samplegroup; run; run; %end; %end; %mend alloc;
proc datasets library=work; delete samplegroup samplesizes; run; quit;
proc sort data=allocds; by id1;
data _null_; set allocds; by id1; rc = dosubl(cats('%alloc(',id1,',',n,')')); run;
... View more