09-18-2014 11:07 AM
Does anyone know of any alternatives to using the Best format? I am using the Best format to convert a numeric variable to character and would like to keep the same number of decimals originally present in the numeric variable. However I'm getting more decimal places on certain occasions. For instance, I have a variable - height and it has a value of 88.8. After doing charheight=put(height,best.). I am getting a value of 88.81 as opposed to 88.8. The Best format does this sometimes. I've seen this happen in 9.1 and 9.3 versions. Does anyone know of any trick of alternative to using the Best format in order to preserve the same number of decimal places present in the numeric variable while converting it to character?
09-18-2014 11:30 AM
It shouldn't do. Are you sure the variable where you are getting 88.81 from doesn't have a format applied? I.e the actual value is 88.81, however the variable has a 4.1 format applied hence you don't see the 1? If not please post a specific example where this is happening.
09-18-2014 02:57 PM
This code doesn't replicate the problem:
c=put( x, best.);
Time to show what is generating your 88.8 and what you did afterwards.
09-18-2014 06:18 PM
I assume that if the best. format gives you 8.81 then the actual numeric value had been 8.81. You might have seen 8.1 only because there was already a format on the variable. So if you want in the character variable what you've seen before then use exactly the same format as already on the variable.
If you believe above isn't the reason for what you encounter then could you please post a code sample with data which demonstrates the issue?
09-18-2014 10:54 PM
09-18-2014 08:08 PM
Did you try using VVALUEX() function?
Try this example.
format x 4.1 ;
put (_all_) (=/);
09-18-2014 10:48 PM
Your original question is based on a false premise. There is no such thing as a number of decimals present in a numeric variable. There is only a value that is stored. You may have observed a number of decimals present in a report, but that is a feature of the reporting procedure. It is not a feature of the variable itself.
If you want a certain number of decimal positions, use a different format. All of these are legal statements:
newvar1 = put(temp, best8.);
newvar2 = put(temp, 4.1);
newvar3 = put(temp, 5.2);
Pick the one you want. Just don't think of the number of decimal positions as being a characteristic of the data. It isn't. It's only a characteristic of a report.
09-18-2014 10:58 PM
09-19-2014 03:52 AM
Unfortunately I don't use Facebook and hence those links will be unavailable. The posts have all suggested the same things above so if you would like to see a result, please post the text, test data, and example code of where this is happening. If it really does do what you say it does then its a serious issue and needs to be reported to SAS via a helpdesk ticket.