BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kamal5522
Obsidian | Level 7
Hi Could you please advise how to input a single column that can have/read both character & number but should read number as numeric not as character. Is it possible ?
1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

As @heffo  already said: this is not possible. A variable is either numeric or alphanumeric. And if i see notes like

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).

in a log, i would mark the code as defective.

View solution in original post

4 REPLIES 4
heffo
Pyrite | Level 9

As far as I know, it is not possible.

 

What is it that you are trying to achieve? Is it about how to read the input data? Then you might want to think about how to find out if it is a number or not. 

data want;
	something = "-1.03";
	if compress(something,"0123456789-.,","K") = something then do;
		*It is numeric, then maybe do an input statment to remove decimal chars or what ever it is you want.;
	end;
	else do;
		*It is numeric, just let it be.;
	end;
	*You might want to check for missing values, as in " " or ".". ;
run;

 

Is it about how to use the data once it is in the table? 

data want;
	something = "-1.03";
	somethingElse = something * 10;
*This works, but you get a note in the log file.
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
Better not to use it this way if you can avoid it. Maybe combine it with the above code.;
run;

 

SASKiwi
PROC Star

Try this - un-comment var = statements one at a time:

 

data test;
  var = 123;
  * var = '123';
  if vtype(var) = 'C' then varnum = input(var,best12.);
  else varnum = var;
  put _all_;
run; 
andreas_lds
Jade | Level 19

As @heffo  already said: this is not possible. A variable is either numeric or alphanumeric. And if i see notes like

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).

in a log, i would mark the code as defective.

ballardw
Super User

@Kamal5522 wrote:
Hi Could you please advise how to input a single column that can have/read both character & number but should read number as numeric not as character. Is it possible ?

Example data.

If the character values are limited and with a possibly numeric meaning such as NA or NULL that should be missing, or MAX that should be considered a specific value, then possibly. If you have actual mixed data like person names and a numeric value, then not without a lot of parsing code.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 2065 views
  • 3 likes
  • 5 in conversation