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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.