wcguo94 发表于 2011-7-7 10:45 
现需要做一项调查,要求按照变量GDP进行PPS抽样,要求:按照GDP大小成比例抽取20个地区样本,请问采用SAS如何实现?谢谢
Region GDP
Beijing 11865.9
Tianjin 7500.8
Hebei 17026.6
Liaoning 15065.6
Shanghai 14900.9
Jiangsu 34061.2
Zhejiang 22832.4
Fujian 11949.5
Shandong 33805.3
Guangdong 39081.6
Hainan 1646.6
Shanxi 7365.7
Jilin 7203.2
Heilongjiang 8288.0
Anhui 10052.9
Jiangxi 7589.2
Henan 19367.3
Hubei 12831.5
Hunan 12930.7
Chongqing 6528.7
Sichuan 14151.3
Guizhou 3893.5
Yunnan 6168.2
Tibet 441.4
Shaanxi 8186.7
Gansu 3382.4
Qinghai 1081.3
Ningxia 1334.6
Xinjiang 4273.6
InnerMongolia 9725.8
Guangxi 7700.4
试试这个:
data tmp2;
id=_n_;
input region $ gdp;
cards;
Beijing 11865.9
Tianjin 7500.8
Hebei 17026.6
Liaoning 15065.6
Shanghai 14900.9
Jiangsu 34061.2
Zhejiang 22832.4
Fujian 11949.5
Shandong 33805.3
Guangdong 39081.6
Hainan 1646.6
Shanxi 7365.7
Jilin 7203.2
Heilongjiang 8288.0
Anhui 10052.9
Jiangxi 7589.2
Henan 19367.3
Hubei 12831.5
Hunan 12930.7
Chongqing 6528.7
Sichuan 14151.3
Guizhou 3893.5
Yunnan 6168.2
Tibet 441.4
Shaanxi 8186.7
Gansu 3382.4
Qinghai 1081.3
Ningxia 1334.6
Xinjiang 4273.6
InnerMongolia 9725.8
Guangxi 7700.4
;
proc sort;by gdp;
run;
%macro ranselect(data,method=,samprate=,n=,total=,out=,strata=, var=,export=0);
options nodate nonumber ps=100 ls=90;
%if &data ne %then %do;
%if &strata ne %then %do;proc sort data=&data;by &strata;%end;
%if &n ne %then %do;
proc surveyselect data=&data seed=20060704 method=&method n=&n out=&out;%end;
%if &samprate ne %then %do;
proc surveyselect data=&data seed=20060704 method=&method samprate=&samprate out=&out;%end;
%if strata ne %then %do;strata &strata;%end;
%if &var ne %then %do;id &var;%end;run;%end;
%else %do;
data aaaa;do id=1 to &total;output;end;run;
%if &strata ne %then %do;proc sort data=aaaa;by &strata;%end;
%if &n ne %then %do;
proc surveyselect data=aaaa seed=20060704 method=&method n=&n out=&out;%end;
%if &samprate ne %then %do;
proc surveyselect data=aaaa seed=20060704 method=&method samprate=&samprate out=&out;%end;
%if strata ne %then %do;strata &strata;%end;
%if &var ne %then %do;id &var;%end;run;
%end;
%if &export=0 %then %do;proc print data=&out noobs;run;%end;
%else %do;
proc export data=&out outfile='d:\tmp\ranselect.xls' dbms=excel2000 replace;%end;run;
ods select none;
proc datasets;delete &out;run;quit;ods select all;
%mend ranselect;
%ranselect(tmp2,method=srs,samprate=,n=20,total=31,out=bbbb,strata=,var=id region gdp,export=1);