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?
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;
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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: