Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting string to num (keeping decimal)

Status
Not open for further replies.

iren

Technical User
Mar 8, 2005
106
US
Hello everybody,

I have a problem with converting a string to num.

myVAR contains values 5.2 8.7 9.4 and etc.

all of them are strings.

I need to convert them to numeric so that they keep their decimal digits (if any)

How can I do it?

Thank you in advance,

Iren
 
Irene,
You can use the input function:

ex.
x="2.9";
y=input(x,8.2);

Remember that you need to anticipate the decimal places in advance. If you think that your data will have 10 places use the 8.10 in the format section of the input function.

Klaz
 
Klaz - Deliberate error there? In a format, the first number is the total number of characters to be output (including decimal point, dollar signs etc) and the second number is the number of decimal places. Therefore in a format w.d, w must be bigger than d. :)

You made me doubt myself for a moment there and I had to go test it. :)

Code:
3      format var1 8.10;
                   ----
                   156
ERROR 156-185: The decimal specification of 10 must be less than the width specification of 8.
 
Chris,
I was discussing the informat feature. This will run correct.
data _null_;
x='2.9';
y=input(x,8.12);
run;
the informat is what you expect not the actual length.
Hope that this helps.
Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top