Dear all,
I have a rounding issue and here is the simplified code:
data a;
format c $5.;
b= '1.04';
c = left(round(b, 0.1));
run;
The output: c= 1.
However, the desired output must be 1.0 not 1
It is possible to apply different SAS function as solution to add '.0' to 1 if it is too sharply rounded, but I wonder whether is an easy solution.
Thanks and best regards,
Cornelis
how about
data _null_;
b = '1.04';
c = put(round(input(b, 8.2), .1), 8.1 -l);
put b = / c = ;
run;
how about
data _null_;
b = '1.04';
c = put(round(input(b, 8.2), .1), 8.1 -l);
put b = / c = ;
run;
Hi Peter,
This is a reasonable good solution, the put statement in combination with format can be quickly applied in the existing programming code.
Thank you,
Cornelis
The real question here is: why are numbers used for calculations stored in a character variable, which makes handling them unnecessarily hard?
Keep in mind that computers should make your life easier with every step, not harder.
Dear Kurt,
The situation is less easy.
I received a large set of data from a database system and the column contains the next value in character:
0.12
0.6
93.6
93.0
11200
25.1
The values (characters) in a column of a table are all correctly rounded because it depends on the level of analytical instrument.
One instrument rounds with no digit, the other with 1 or 2. That is therefore the reason why I get dataset with character format.
Best regards,
Since you want to discard information (everything after the first decimal), these numbers seem to be real numeric values and not some type of category. In this case, you are better off omitting the re-conversion to character and store the data in a numeric variable with a format that has one digit after the decimal dot.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.