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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.