I am trying to write simple programs and can't seem to get started with what I am trying to do. I'm obviously making a simple error(s) but I can't find what this is. Other programming guides don't address this problem directly.
I have a simple SAS program for calculating the sample size for a diagnostic test:
Code:
title1 'Choosing Sample Size for Evaluating a Diagnostic Test'; data main; *watch "l's" and "1's" !!; label sn = 'sensitivity' sp = 'specificity' p = 'prevalence of disease' w = 'width of 95% CI' a_c = '#diseased subjects TP+FN' b_d= '#non-diseased subjects FP+TN' n_1 = 'sample size for SN' n_2 = 'sample size for SP' n = 'total #subjects N'; *step 1 specifications; sn = 0.90 ; *substitute your value for sensitivity here; sp = 0.85 ; *substitute your value for specificity here; p = 0.20 ; *substitute your value for prevalence here; w = 0.10 ; *substitute your value for width here; *step 2 calculate TP+FN; a_c = (1.96*1.96)*(sn)*(1-sn)/(w*w); *step 3 calculate N1; n_1 = a_c/p; *round up to the next whole integer; n_1int = int(n_1); if n_1 ne n_1int then n_1 = n_1int + 1; *step 4 calculate FP+TN; b_d = (1.96*1.96)*(sp)*(1 -sp)/(w*w); *step 5 calculate N2; n_2 = b_d/(1 -p); *round up to the next whole integer; n_2int = int(n_2); if n_2 ne n_2int then n_2 = n_2int + 1; * step 6 get final sample size; if n_1 gt n_2 then n=n_1; else if n_2 gt n_l then n=n_2; else if n_1=n_2 then n=n_1; run; * print the sample size; proc print label noobs; var w sn sp p n_1 n_2 n; run;
Code:
*! senspecsamp.ado program define senspecsamp, rclass version 16.1 syntax , sen(real) spec(real) prev(real) conint(real) tempname ac bd gen `ac' = (1.96*1.96)*(`sen')*(1-`sen') /(`conint'*`conint') gen `bd'= (1.96*1.96)*(`spec')*(1 -`spec') / (`conint'*`conint') tempname n1 n2 gen `n1' = (`ac'/ `prev') gen `n2'= (`bd'/ (1-`prev')) tempname N1 N2 gen `N1'=ceil(`n1') gen `N2'=ceil(`n2') return scalar n = max(`N1' `N2') display in smcl as text _newline(1) "Sample size for test = " return(n) end
Thanks
Chris
0 Response to Hint to start programming
Post a Comment