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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
6 REPLIES 6
Kurt_Bremser
Super User

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)

vraj1
Quartz | Level 8

Yes, But not all variables have that funny symbol in the start.

For example see the screenshot. but for some variables it is proper.

 


Capture.JPG
Shmuel
Garnet | Level 18

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.

 

 

 

 

 

Shmuel
Garnet | Level 18

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 ?

Ksharp
Super User
temp1=prxchange('s/^\s+//',1,temp);

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
  • 6 replies
  • 997 views
  • 1 like
  • 4 in conversation