******************************************************************************************************************************************************** This SAS macro computes the one-sided and two-sided EXACT confidence interval for CV (coefficient of variation) when data is from a Normal distribution version 1.0 21MAR2019 Input: dat - name of SAS data set for input varlist - list of variables for CI calcualtion of CV conflevel - default as 0.95 if not specified correctly, ideally between 0.5 and 1 Output: fin - name of SAS data set for output _NAME_ : name of variables n : sample size mean : mean value std : standard deviation value conflevel : confidence interval value cv : coefficient of variation estimate cv_twosided_low : two-sided confidence interval of CV's lower value, P(cv_twosided_low< CV cv_onesided_low)=conflevel for Normal data cv_onesided_high : P(CV < cv_onesided_high)=conflevel for Normal data For any question or suggestion, email icalcucom@gmail.com https://www.icalcu.com/SASmacro/exact_confidence_interval_for_coefficient_of_variation.txt *******************************************************************************************************************************************************; %macro cicv(dat,varlist, conflevel); proc means data=&dat mean std nway noprint; var &varlist; output out=tm (drop=_type_ _freq_); run; proc transpose data=tm out=tmt prefix=statname_; where _stat_ in ('N','MEAN','STD'); run; data fin; set tmt; n=statname_1; mean=statname_2; std=statname_3; conflevel=&conflevel; conflevel=max(conflevel, 1-conflevel); if conflevel<=0 or conflevel>=1 or conflevel=. then conflevel=0.95; cv=std/mean; cv_twosided_low=sqrt(n)/tnonct(sqrt(n)*mean/std,n-1,0.5-0.5*conflevel); cv_twosided_high=sqrt(n)/tnonct(sqrt(n)*mean/std,n-1,0.5+0.5*conflevel); cv_onesided_low=sqrt(n)/tnonct(sqrt(n)*mean/std,n-1,1-conflevel); cv_onesided_high=sqrt(n)/tnonct(sqrt(n)*mean/std,n-1,conflevel); drop statname_1 statname_2 statname_3 ; run; proc print data=fin noobs; run; %mend; *Example - from Johannes Forkman Thesis on CV, Page 20 https://www.researchgate.net/publication/30072742_Coefficients_of_variation ; data test; input v1 v2; cards; 326 326 302 302 307 307 299 299 329 329 ; run; %cicv(test,v1 v2, 0.95 )