i have a variable in the dataset and it has characters which start with a weird space or square like thing.
I need to remove it whereever it is there in the variable list. Can any one help me in it.
First I'd recommend to convert the contents of your variable to a new variable of double length with a $hex format.
Assuming that oldvar is $6:
newvar = put(oldvar,$hex12.);
Now you can determine what exactly is behind the funny symbol, and can use that hex code to decide when the first character should be stripped using the substr() function and when not. Use the hex code in a literal as "NN"x (NN being hex digits 0-9,a-f)
Yes, But not all variables have that funny symbol in the start.
For example see the screenshot. but for some variables it is proper.
Since this is program code, it looks to me like the result of a failed character code conversion when transferring the file from one system to another.
The rectangle means it is a non printable character and is not in your font set of characters.
I would start with searching the origin of data because removing characters means you change the data.
On your capture I saw 0 to 2 rectangles and maybe there are more, even in middle of a variable;
Those can be different characters, not neccessary the same one;
in case you recognize specific hexa characters you can replace then to any character(s) you chose
using TRANSLATE function:
ne_var = translate(old_var, new_chars, old_chars);
new_chars and old_chars should fit by order.
you can remove 1st character by:
var = substr(var,2);
Do you know the origin of your data? how did you get the variable with that extra character ?
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 25. Read more here about why you should contribute and what is in it for you!
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.