For three significant figures, the SAS Institute provides the following code snippet to accomplish the task.
However, it is often useful to round to more or less than 3 significant figures. I’ve developed a macro to do so for my own use and am sharing the code below.
%macro _nsigfig(varin=, varout=, n=);
if &varin. = 0 then &varout. = 0;
else do;
if int(&varin.) ^= 0 then do;
&varout. = round(&varin., 10**(int(log10(abs(&varin.))) + (1 - &n.)));
end;
else do;
&varout. = round(&varin., 10**(-1*(abs(int(log10(abs(&varin.)))) + &n.)));
end;
end;
%mend _nsigfig;
Tags: pharma sas sigfig significant figures