You are using the wrong informat:
input(z, 8.2)
You should be using:
input(z, 8.)
If you use 8.2, it is telling SAS to look for a decimal point. If it doesn't find one, assume the last two digits belong after the decimal point.
Z is already a variable. So I'm not sure what question you are asking. At any rate .....
The meaning of 8.2 doesn't change. It still means to read 8 characters, and see if they contain a decimal point. If there is a decimal point, use it. But if there is no decimal point, assume the last two digits should fall after the decimal point.
If your original variable is numeric, rather than character, you are asking for trouble using the INPUT function. The INPUT function expects to read a character string.
@mrdlau wrote:
I have a variable z=10, but in a character format.
To multiply it by 2, i convert the z to a numeric during my multiplication:
2*input(z, 8.2).
However, my result is .2, not 20. Why is this the case? It is onlu 20 when I use input(z, 8.)
You might try a simple
x = 2*z;
and examine the result and the log.
SAS will attempt to convert character values to numeric to do computations like this in a data step. The conversion is usually pretty good. Though if you want to do calculations the question is always why was the variable created as character in the first place.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.