Statistical programming, matrix languages, and more

conversion from character to numeric

Reply
Frequent Contributor
Posts: 84

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

Super Contributor
Posts: 490

Re: conversion from character to numeric

use input statment

like:

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

Check: Converting a Character Variable to a Numeric Variable

Frequent Contributor
Posts: 84

Re: conversion from character to numeric

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

SAS Super FREQ
Posts: 3,221

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.

Frequent Contributor
Posts: 84

Re: conversion from character to numeric

Will this work within proc IML ?

SAS Super FREQ
Posts: 3,221

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.

Frequent Contributor
Posts: 84

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>>);

Super Contributor
Posts: 490

Re: conversion from character to numeric

ijn=input(ij, 2.0);

SAS Super FREQ
Posts: 3,221

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.");

Frequent Contributor
Posts: 84

Re: conversion from character to numeric

I use following command and its work for me

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

SAS Super FREQ
Posts: 3,221

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 */

Post a Question
Discussion Stats
  • 10 replies
  • 494 views
  • 0 likes
  • 3 in conversation