DATA Step, Macro, Functions and more

unexpected conversion from number to character, SAS v 9.4

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

unexpected conversion from number to character, SAS v 9.4

After importing an Excel file with a numeric variable, Var1, I'm getting the following error:

 

    "NOTE: Numeric values have been converted to character values at the places given by..."

 

I've tried the following statements, but still get the same error. What might be causing this & what's the fix?  There are no character values in the data.

 

   new9=input(Var1,4.1);
   drop Var1;
   rename new9=Var1;

 


Accepted Solutions
Solution
‎01-12-2017 10:03 PM
Super User
Posts: 5,099

Re: unexpected conversion from number to character, SAS v 9.4

Why is it that you think VAR1 was character after the import?  Did you run a PROC CONTENTS?

 

Your code might be correct for a character VAR1.  (It also might not ... the 4.1 informat will insert a decimal point if it doesn't find one in the incoming string, but that's a secondary issue.)

 

The fact that you are getting the conversion message when you execute your sample statements means that VAR1 is already numeric.  The software had to convert it to character in order to apply the INPUT function.  Run a PROC CONTENTS before fiddling with the data to find out which variable is the real troublemaker.

View solution in original post


All Replies
PROC Star
Posts: 7,366

Re: unexpected conversion from number to character, SAS v 9.4

According to the documentation: Use INPUT to convert character values to numeric values or other character values.

 

If it's already numeric, you should just rename it (if desired) and apply whatever format you want for the variable.

 

Art, CEO, AnalystFinder.com

 

New Contributor
Posts: 2

Re: unexpected conversion from number to character, SAS v 9.4

Is my code snippet incorrect?
PROC Star
Posts: 7,366

Re: unexpected conversion from number to character, SAS v 9.4

Sounds like you only want/need something like:

 

data want;
  set have (rename=(var1=var9));
  format var9 4.1;
run;

Solution
‎01-12-2017 10:03 PM
Super User
Posts: 5,099

Re: unexpected conversion from number to character, SAS v 9.4

Why is it that you think VAR1 was character after the import?  Did you run a PROC CONTENTS?

 

Your code might be correct for a character VAR1.  (It also might not ... the 4.1 informat will insert a decimal point if it doesn't find one in the incoming string, but that's a secondary issue.)

 

The fact that you are getting the conversion message when you execute your sample statements means that VAR1 is already numeric.  The software had to convert it to character in order to apply the INPUT function.  Run a PROC CONTENTS before fiddling with the data to find out which variable is the real troublemaker.

Super User
Posts: 17,963

Re: unexpected conversion from number to character, SAS v 9.4

Proc import wouldn't generate that error, so what's the code that generates the error. 

 

Was the import correct, is the value read in correctly? Proc import guesses when importing since Excel doesn't follow any database standards so the data can be anything. 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 145 views
  • 0 likes
  • 4 in conversation