Dear all,
i've a dataset like given bellow
A | B | C | D |
---|---|---|---|
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 |
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.
A | B | C | D |
---|---|---|---|
N | 36 | 36 | 36 |
Mean | 9581.172 | 9791.526 | 1366.1 |
SD | 2965.862 | 2982.074 | 398.35 |
Geo_Mean | 9170.286 | 2.086 | 1312.3 |
CV | 13.955 | 13.455 | 0.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?
Thanks in advance
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;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.