Hi Guys,
I want to apply different precision to the same variable depending on other variable value without using round function.
TABLE
Value | Decimal place |
---|---|
1 | 1 |
2.3 | 3 |
0 | 4 |
3.5678 | 2 |
0.0002 | 5 |
4.4034 | |
1.703 | 0 |
DESIRABLE OUTPUT
Value | Decimal place | Final value |
---|---|---|
1 | 1 | 1.0 |
2.3 | 3 | 2.300 |
0 | 4 | 0.0000 |
3.5678 | 2 | 3.56 |
0.0002 | 5 | 0.00020 |
4.4034 | 4.4034 | |
1.703 | 0 | 1 |
Sorry, I just assumed he didn't want to use that function, not that he didn't want rounding. I would assume the only reason not to use rounding would be significant figures? If some then its a fair bit more complicated, though there are quite a few formulae on the net to do that - or of course just use string functions.
I don't disagree but looking at 's final value column implies that D is truncated. The problem is vague at best.
This might work. Assuming character value.
I would like to use PUTN as RW9 suggested, and proc format wouldn't round it .
data have; infile cards dlm=' ' truncover; input value d; format value 10.0 ; cards; 1 1 2.3 3 0 4 3.5678 2 0.0002 5 4.4034 1.703 0 ;;;; run; proc format; picture dec0_ low-high='9'; picture dec1_ low-high='9.9'; picture dec2_ low-high='9.99'; picture dec3_ low-high='9.999'; picture dec4_ low-high='9.9999'; picture dec5_ low-high='9.99999'; run; data have; set have; format=ifc(missing(d),'best32.',cats('dec',d,'_')); new=putn(value,format); run;
Xia Keshan
Thanks all for your suggestions. Variable (column) labeled as VALUE is numeric.
I didn't wanted to use round function because
SAY
A=0.696
B=0.7
if A=B then color=RED
if A <B then color=GREEN
I am exporting these values to a dashboard where variable A value should appear as one decimal precision.
now if I use ROUND(A,0.1) THEN A value would be 0.7, In the dashboard value of A AND B would appear as 0.7 and COLOR value as GREEN.
Thanks
Shiv
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.