options nomprint; options mstored sasmstore=ex1; data margins; input var $ n mar1 mar2 mar3 mar4 mar5 mar6 mar7 mar8 mar9; CARDS; CTBAND 9 24.83 24.62 15.45 11.91 11.96 5.95 3.94 0.45 0.89 tenure 4 62.63 21.59 5.58 10.20 . . . . . ; TITLE 'RAKING WITH CALMAR'; %calmar(data=ex1.ex1,poids=GROSS2,ident=SERNUM,datamar=margins,M=2, editpoi=oui,obseli=oui,datapoi=newdata,poidsfin=newweight, labelpoi='new weight',pct=oui,effpop=2242012); proc sort data=ex1.ex1; by sernum; proc sort data=newdata; by sernum; data poststrat; * this is the new complete data set with the raked weights; merge ex1.ex1 newdata; by sernum; run; proc format ; value tenure 1='owned' 2='rented LA' 3='oth pub rent' 4='private rent or rent free'; value CTBAND 1='A' 2='B' 3='C' 4='D' 5='E' 6='F' 7='G'8='H' 9='not sep valued'; run; proc gplot data=poststrat; * check to see how much weights have changed; plot newweight*gross2=tenure; plot newweight*gross2=ctband; format tenure tenure. ; run; proc surveymeans data=poststrat mean stderr; * introducing clusters ; weight newweight; cluster psu; var hhinc; run; ods html file='example.htm' path='c:\' (url=none) style=minimal; %macro makejkwts(data=ex1.ex1,origwt=GROSS2,out=jck,psu=PSU,npsu=320, effpop=2242012,sernum=SERNUM,M=2,margins=margins); * first rake the original data set; %calmar(data=&data,poids=&origwt,ident=&sernum,datamar=&margins,M=&M, editpoi=non,obseli=oui,datapoi=alldata,poidsfin=newweight, pct=oui,effpop=&effpop,stat=non); data &out; merge alldata &data; run; proc sort data=&out; by sernum; %do nrep=1 %to &npsu; data new; set &data; if &psu=&nrep then &origwt=0; run; %calmar(data=new,poids=&origwt,ident=&sernum,datamar=&margins,M=&M, editpoi=non,obseli=oui,datapoi=newdata,poidsfin=newweight&nrep, pct=oui,effpop=&effpop,stat=non); data new; set newdata __obseli (in=excl); if excl then newweight&nrep=0; keep &sernum newweight&nrep; run; proc sort data=new; by &sernum; run; data &out ;merge &out new; by sernum; run; %end; %mend; %makejkwts(out=ex1.ex1repwts); ods html close;