*--------------------------------------------------------------; * computes ratio estimate, estimate of population R, mean, or ; * from a simple random sample with auxiliary variable X. ; *--------------------------------------------------------------; %macro ratio(sample=,setup=,npop=,n=,response=,param=,x=,tau_x=, mu_x=,fpc=); %if %length(&sample) = 0 %then %let sample = %str(sample); %if %length(&npop) = 0 %then %let npop = %str(npop); %if %length(&x) = 0 %then %let x = %str(x); %if %length(&fpc) = 0 %then %do; %let fpc_ = %str( (&npop - n_) / &npop ); %if %length(&tau_x) > 0 %then %let mu_x = %str(&tau_x/&npop); %end; %else %do; %let fpc_ = 1; %end; %if %length(&mu_x) = 0 %then %let mu_x = %str(xbar_); data mux_; set &sample(keep = &x &response); cp_ = &x*&response; proc means data = mux_ noprint; var &response &x cp_; output out = est_ mean = ybar_ xbar_ sum = sumy_ sumx_ sumxy_ n = n1_ n2_ n_ css = ssyy_ ssxx_; %if %length(&setup) > 0 %then %do; data est_; merge est_ &setup; %end; %else %do; data est_; set est_; %end; r_ = sumy_/sumx_; ssxy_ = sumxy_ - sumx_*sumy_/n_; sr2_ = (ssyy_ + r_**2*ssxx_ - 2*r_*ssxy_ )/(n_-1); var_r_ = &fpc_*sr2_/(n_*(&mu_x)**2); std_r_ = sqrt(var_r_); bnd_r_ = 2*std_r_; mu_hat_ = &mu_x*r_; std_mu_ = &mu_x*std_r_; bnd_mu_ = 2*std_mu_; %if %length(&fpc) = 0 %then %do; tau_hat_ = &npop*mu_hat_; std_tau_ = &npop*std_mu_; bnd_tau_ = 2*std_tau_; %end; %else %do; tau_hat_ = &tau_x*r_; std_tau_ = &tau_x*std_r_; bnd_tau_ = &tau_x*bnd_r_; %end; %if %index(%upcase(¶m),R) > 0 %then %do; proc print data = est_ noobs split='*'; title1 'Ratio Estimate of Population R'; title2 'Simple Random Sample Design'; title3 "Response Variable = &response"; title4 "(Auxiliary Variable = &x)"; label r_ = 'Estimate'; label std_r_ = 'Standard*Error'; label bnd_r_ = 'Bound'; label sr2_ = 's(r)^2'; label n_ = 'Sample*Size'; var r_ std_r_ bnd_r_ sr2_ n_; %end; %if %index(%upcase(¶m),MEAN) > 0 %then %do; proc print data = est_ noobs split='*'; title1 'Ratio Estimate of Population Mean'; title2 'Simple Random Sample Design'; title3 "Response Variable = &response"; title4 "(Auxiliary Variable = &x)"; label mu_hat_ = 'Estimate'; label std_mu_ = 'Standard*Error'; label bnd_mu_ = 'Bound'; label sr2_ = 's(r)^2'; label n_ = 'Sample*Size'; var mu_hat_ std_mu_ bnd_mu_ sr2_ n_; %end; %if %index(%upcase(¶m),TOTAL) > 0 %then %do; proc print data = est_ noobs split='*'; title1 'Ratio Estimate of Population Total'; title2 'Simple Random Sample Design'; title3 "Response Variable = &response"; title4 "(Auxiliary Variable = &x)"; label tau_hat_ = 'Estimate'; label std_tau_ = 'Standard*Error'; label bnd_tau_ = 'Bound'; label sr2_ = 's(r)^2'; label n_ = 'Sample*Size'; var tau_hat_ std_tau_ bnd_tau_ sr2_ n_; %end; run; title; %mend ratio;