Contributor
Posts: 26

# How to give Significant digits and decimal places in SAS

Dear all,

i've a dataset like given bellow

ABCD
N363636
Mean9581.17289791.52621366.1106
SD2965.86262982.0749 398.3543
Geo_Mean9170.2867 2.0864674 1312.3213
CV13.95511 13.455669 0.159741

Now i need to give 3 decimal places for the variables 'B' & 'C', and 5 significant digits for the variable 'D'. But these decimal places and significant digits should not be applyed for observations of 'N'. i had tried many things like format, length and etc. but it didn't work well. the output should be like given bellow.

ABCD
N363636
Mean9581.1729791.5261366.1
SD2965.8622982.074398.35
Geo_Mean9170.2862.086 1312.3
CV13.955 13.4550.15974

i'm excited to find is it really possible? if so, can anyone tell me how? or it is possible by transforming the variables?

SAS Employee
Posts: 1,042

## Re: How to give Significant digits and decimal places in SAS

[ Edited ]

Here's one brute-force way to do it, converting the numeric values to character, and controlling the number of decimals shown when you create the character values:

``````data foo;
length A \$50;
input A B C D;
datalines;
N	36	36	36
Mean	9581.1728	9791.5262	1366.1106
SD	2965.8626	2982.0749	398.3543
Geo_Mean	9170.2867	2.0864674	1312.3213
CV	13.95511	13.455669	0.159741
;
run;

data foo; set foo;
length B_string C_string D_string \$20;
if A='N' then do;
B_string=put(B,comma5.0);
C_string=put(C,comma5.0);
D_string=put(D,comma5.0);
end;
else do;
B_string=put(B,comma20.3);
C_string=put(C,comma20.3);
D_string=put(D,comma20.1);
end;

proc print data=foo noobs label;
label B_string='B' C_string='C' D_string='D';
var A / style={just=center};
var B_string / style={just=right};
var C_string / style={just=right};
var D_string / style={just=right};
run;``````

Discussion stats