DATA Step, Macro, Functions and more

convert the character to numeric

Reply
Regular Contributor
Posts: 241

convert the character to numeric

Hello,

why I can't convert the character m to numeric s?

 

data a;

m='12345678';

run;

data b;

set a;

s=put(m, $8.);

run;

 

Thanks

Super User
Posts: 11,343

Re: convert the character to numeric

Posted in reply to GeorgeSAS

PUT always creates a character variable used the way you did

 

Try

data b;

set a;

s= input(m, 8.);

run;

 

 

 

Regular Contributor
Posts: 241

Re: convert the character to numeric

thank you, but s is still a char.

Super User
Posts: 19,789

Re: convert the character to numeric

Posted in reply to GeorgeSAS

It shouldn't be. Double check your code and output. Was your log clean? Is S already in your dataset, you can't change a variable type if it already exists in the dataset.

 

data a;
m='12345678';
run;
data b;
set a;
s=input(m, 8.);
run;

proc contents data=b;
run;

Alphabetic List of Variables and Attributes

#Variable Type Len

1m Char 8

2 s Num 8

Regular Contributor
Posts: 241

Re: convert the character to numeric

I found the problem, the import excel file including special characters which make SAS function can't recginize that variable.

the special characters are something like ctrl+ enter in excel.

Ask a Question
Discussion stats
  • 4 replies
  • 250 views
  • 0 likes
  • 3 in conversation