DATA Step, Macro, Functions and more

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

Accepted Solution Solved
Reply
Contributor LL5
Contributor
Posts: 44
Accepted Solution

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

Hi, I try to create three new indicator columns. These indicators are character filed. When I run my code, I got the below message. It seems SAS converted these fields to numeric value. What should I do?

Thanks

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

      21:22   22:28  

NOTE: Invalid numeric data, 'Y' , at line 22 column 36.

NOTE: Invalid numeric data, 'Y' , at line 22 column 36.

 

 

DATA TEST;

SET ABC;

ARRAY OLD (3) INDICATOR1 INDICATOR2 INDICATOR3;

ARRAY NEW (3) INDICATOR1_NEW INDICATOR2_NEW INDICATOR3_NEW;

DO I = 1 TO 3;

IF OLD(I) = "N" THEN NEW(I)= " ";

ELSE IF OLD(I) NE "N" THEN NEW(I) =OLD(I);

END;

 

DROP I;

RUN;

 


Accepted Solutions
Solution
‎09-01-2016 05:24 PM
Super User
Posts: 11,343

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

It would probably be easiest just to assign them all the same max length of $2. If the actual length becomes an issue you can specify a Length statment for the new variables before putting them in the Array definition such as

 

Length INDICATOR1_NEW $ 1 INDICATOR2_NEW INDICATOR3_NEW $ 2;

 

BTW I would recommend using New_Indicator1, New_Indicator2 etc. For a number of reasons. It is easy to specify variable lists such as New_I: to get all variables that start with New_I for almost anything that accepts a list of variable names.

 

For instance your array definition could be

 

Array new (3) $2 New_Indicator1 - New_Indicator3;

Which when you get to a project with 25, 50 or more variables makes things a whole lot easier to change that 3 to 25 and be done instead of typing in all 25 variable names.

View solution in original post


All Replies
Super User
Posts: 11,343

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

When you created the array New the variables by default were created as numeric if they did not exist in the data set ABC.

 

ARRAY NEW (3) $1 INDICATOR1_NEW INDICATOR2_NEW INDICATOR3_NEW;

 

would create character variables of length 1. if you need longer than increase the 1 to the needed length.

Contributor LL5
Contributor
Posts: 44

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

Thanks Ballardw. It works now!

What happen if INDICATOR1_NEW has one character, where INDICATOR2_NEW and INDICATOR3_NEW have two characters?

Solution
‎09-01-2016 05:24 PM
Super User
Posts: 11,343

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

It would probably be easiest just to assign them all the same max length of $2. If the actual length becomes an issue you can specify a Length statment for the new variables before putting them in the Array definition such as

 

Length INDICATOR1_NEW $ 1 INDICATOR2_NEW INDICATOR3_NEW $ 2;

 

BTW I would recommend using New_Indicator1, New_Indicator2 etc. For a number of reasons. It is easy to specify variable lists such as New_I: to get all variables that start with New_I for almost anything that accepts a list of variable names.

 

For instance your array definition could be

 

Array new (3) $2 New_Indicator1 - New_Indicator3;

Which when you get to a project with 25, 50 or more variables makes things a whole lot easier to change that 3 to 25 and be done instead of typing in all 25 variable names.

Contributor LL5
Contributor
Posts: 44

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

Great. Thanks. This is very helpful.
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 1753 views
  • 2 likes
  • 2 in conversation