*--------------------------------------------------------------; * computes difference estimate, estimate of population mean, ; * or total from a simple random sample with auxiliary ; * variable X. ; *--------------------------------------------------------------; %macro diff(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); d_ = &response - &x; proc means data = mux_ noprint; var d_ &response &x; output out = est_ mean = dbar_ ybar_ xbar_ var = sd2_ n = n1_ n2_ n_; %if %length(&setup) > 0 %then %do; data est_; merge est_ &setup; %end; %else %do; data est_; set est_; %end; mu_hat_ = &mu_x + dbar_; var_mu_ = &fpc_*sd2_/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 "Difference Estimate of the 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 sd2_ = 's(d)^2'; label n_ = 'Sample*Size'; var mu_hat_ std_mu_ bnd_mu_ sd2_ n_; %end; %if %index(%upcase(¶m),TOTAL) > 0 %then %do; proc print data = est_ noobs split='*'; title1 "Difference Estimate of the 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 sd2_ = 's(d)^2'; label n_ = 'Sample*Size'; var tau_hat_ std_tau_ bnd_tau_ sd2_ n_; %end; run; title; %mend diff;