## conversion from character to numeric

I have number like 11 in character form now I have to convert it in numeric number, how can I do this

10 REPLIES 10

## Re: conversion from character to numeric

use input statment

like:

num = input('56',6.);

## Re: conversion from character to numeric

but i have to do in proc IML  and input statement is not working in IML

## Re: conversion from character to numeric

Use the NUM function.  You could also use the INPUTN function if you want to apply a general informat.

## Re: conversion from character to numeric

Will this work within proc IML ?

## Re: conversion from character to numeric

Yes, this is the SAS/IML forum.  If it doesn't work then you should post your code so that we can see what you are trying to do.

## Re: conversion from character to numeric

I stored value 11 in ij

and want to convert it in numeric form with width 2 and decimal place 0 and store in ijn

ijn=inputn(ij,6.<,2<,0>>);

## Re: conversion from character to numeric

ijn=input(ij, 2.0);

## Re: conversion from character to numeric

No, the INPUT function is not supported in SAS/IML.  However, you can use the INPUTN format like this:

ijn = inputn(ij, "Best6.");

## Re: conversion from character to numeric

I use following command and its work for me

ijn=inputn(ij,'6.',2,0);

## Re: conversion from character to numeric

Perhaps you are getting confused by the difference between informats and formats.  When you use the NUM function, it uses a BEST. format to convert the characters to numbers. This is what you want to do.  If you want to display the numbers with a 6.2 format, you can use the FORMAT= option on the PRINT statement, as follows:

proc iml;

x = {"1"  "11"  "2.135"  "8"  "-3.14"};

y = num(x);

print y;                    /* BEST format */

print y[format=6.2];/* 6.2 format */

From The DO Loop