BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LL5
Pyrite | Level 9 LL5
Pyrite | Level 9

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):(Column).

      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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
ballardw
Super User

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.

LL5
Pyrite | Level 9 LL5
Pyrite | Level 9

Thanks Ballardw. It works now!

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

ballardw
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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