*--------------------------------------------------------------; * computes regression estimate, estimate of population mean, ; * or total from a simple random sample with auxiliary ; * variable X. ; *--------------------------------------------------------------; %macro regr(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(&tau_x)> 0 %then %let mu_x = %str(&tau_x/&npop); %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_ = &response*&x; proc means data = mux_ noprint; var &response &x cp_; output out = est_ sum = sumy_ sumx_ sumxy_ css = totalss_ uss = ssqy_ ssqx_ mean = ybar_ xbar_ n = n1_ n2_ n_; %if %length(&setup) > 0 %then %do; data est_; merge est_ &setup; %end; %else %do; data est_; set est_; %end; ssxx_ = ssqx_ - sumx_*sumx_/n_; ssyy_ = ssqy_ - sumy_*sumy_/n_; ssxy_ = sumxy_ - sumx_*sumy_/n_; b1_ = ssxy_/ssxx_; b0_ = ybar_ - b1_ * xbar_ ; ssr_ = ssxy_*ssxy_/ssxx_; sse_ = totalss_ - ssr_; mse_ = sse_/(n_-2); mu_hat_ = b0_ + &mu_x*b1_; var_mu_ = &fpc_*mse_/n_; std_mu_ = sqrt(var_mu_); bnd_mu_ = 2*std_mu_; %if %length(&fpc) = 0 %then %do; tau_hat_ = &npop*mu_hat_; std_tau_ = &npop*std_mu_; bnd_tau_ = &npop*bnd_mu_; %end; %if %index(%upcase(¶m),MEAN) > 0 %then %do; proc print data = est_ noobs split='*'; title1 'Regression Estimate of 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 mse_ = 'MSE'; label b0_ = 'Intercept'; label b1_ = 'Slope'; label n_ = 'Sample*Size'; var mu_hat_ std_mu_ bnd_mu_ mse_ b1_ b0_ n_; %end; %if %index(%upcase(¶m),TOTAL) > 0 %then %do; proc print data = est_ noobs split='*'; title1 'Regression Estimate of 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 b0_ = 'Intercept'; label b1_ = 'Slope'; label mse_ = 'MSE'; label n_ = 'Sample*Size'; var tau_hat_ std_tau_ bnd_tau_ mse_ b1_ b0_ n_; %end; run; title; %mend regr;