Hello,
I have a numeric variable x and i tried to convert to character using: put (x, best32.).
Now, x can have values like 3, 3.0, 3.02 etc...upto 2 decimal places.
How to keep the format as is..i.e 3 -->3, 3.0 --> 3.0 and so on?
Currently, with my code, it is outputting everything as 1 decimal places...and dropping the second decimal.
Thanks very much
It may be that
with my code, it is outputting everything as 1 decimal
is due to the method. Some procedures round for simplicity. Show how you are creating that output.
If you are printing the output then the format is likely an issue. Try assigning a format that forces 2 decimals such as
Format variable f8.2 ;
If the default format is something like best8. and you have values of 12345678.99 then only 8 digits are likely to display and the .99 wouldn't be seen.
Hi,
Just specify the number of decimal places:
data have;
num=3; output;
num=3.01; output;
num=3.1; output;
run;
data want;
set have;
length text $10.;
text=strip(put(num,best8.2));
run;
It may be that
with my code, it is outputting everything as 1 decimal
is due to the method. Some procedures round for simplicity. Show how you are creating that output.
If you are printing the output then the format is likely an issue. Try assigning a format that forces 2 decimals such as
Format variable f8.2 ;
If the default format is something like best8. and you have values of 12345678.99 then only 8 digits are likely to display and the .99 wouldn't be seen.
Sorry, but 3.10 is coming as 3.1, the last 0 is getting dropped.
data have;
num=3; output;
num=3.01; output;
num=3.10; output;
run;
data want;
set have;
length text $10.;
text=strip(put(num,best7.2));
run;
Yes, you can't fix set number of numbers and not use it for all the values like that. So, to fix it to two decimal output you would use z8.2, however the upshot of this is that 3 would become 3.00. That is I am afraid consistency. If you don't want that effect then you will have to pad it yourself in the text field, ie.
temp=strip(substr(index(text,".")+1)); /* This gets you the decimal part */
if length(strip(temp)) < 2 then text=cats(strip(text),repeat("0",length(temp)-1);
The number 3.1 and the number 3.10 are the exact same number. If you want to distinguish between them you will need to store them differently.
You could store them in a character variable.
You could store additional variable(s)
Perhaps store the display format you want : (3.1, 'F3.1') and (3.10,'F4.2')
Or just the number of decimal places (3.1, 1) and (3.10, 2).
You could store them in different variables which could have their own formats attached.
DECIMAL1 = 3.1;
DECIMAL2 = 3.1;
format decimal1 F3.1 decimal2 F4.2 ;
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!
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.