BookmarkSubscribeRSS Feed
Rasheed
Calcite | Level 5

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
mohamed_zaki
Barite | Level 11

use input statment

like:

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

Check: Converting a Character Variable to a Numeric Variable

Rasheed
Calcite | Level 5

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

Rick_SAS
SAS Super FREQ

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

Rasheed
Calcite | Level 5

Will this work within proc IML ?

Rick_SAS
SAS Super FREQ

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.

Rasheed
Calcite | Level 5

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

mohamed_zaki
Barite | Level 11

ijn=input(ij, 2.0);

Rick_SAS
SAS Super FREQ

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

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

Rasheed
Calcite | Level 5

I use following command and its work for me

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

Rick_SAS
SAS Super FREQ

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

sas-innovate-2024.png

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.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 10 replies
  • 2211 views
  • 0 likes
  • 3 in conversation