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

With below code I tend to make a new column based on the values of an other column. When I click run and check the 'column_x' I see just the letter 'F' for criteria 'N' instead of the word `Fixed` and for the else I see just the letter 'N' instead of 'Not fixed'.

 

 

data want;
set have;
if index(criteria,'N') then colum_x= "Fixed";
else column_x= "Not fixed";
run;

It seems like its just taking the first letters inside the parenthesis. Why is that and how can I fix it? 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

This happens because your new variable isn't really new.  HAVE already contains COLUMN_X (or perhaps COLUM_X, whichever spelling you are using) and it has a defined length of $1.  You can change that by adding a LENGTH statement before the SET statement:

 

data want;
length column_x $ 9;
set have;
if index(criteria,'N') then column_x= "Fixed";
else column_x= "Not fixed";
run;

View solution in original post

3 REPLIES 3
Astounding
PROC Star

This happens because your new variable isn't really new.  HAVE already contains COLUMN_X (or perhaps COLUM_X, whichever spelling you are using) and it has a defined length of $1.  You can change that by adding a LENGTH statement before the SET statement:

 

data want;
length column_x $ 9;
set have;
if index(criteria,'N') then column_x= "Fixed";
else column_x= "Not fixed";
run;
ballardw
Super User

If column_x were actually a new variable then the values you would see would be "Fixed" and "Not f".

If you do not explicitly set the length of a new variable then the first use will set the length. In this case that would be "Fixed" which is length 5. So "Not fixed" would be truncated to 5 characters.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 531 views
  • 3 likes
  • 4 in conversation