BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
animesh123
Obsidian | Level 7

Hi I want remove a bad data from a variable . so inthis obs between nicolas and 84989 there is a small icon am trying to remove that using sas in linux environment 

I tried to do the same in sas eg using 

APPLCNT_CMT_TX=compress(APPLCNT_CMT_TX,'');

this is working but in linux environement the same is now working  

 

animesh123_0-1740662700143.jpeg

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

In general I find it is better to write non 7-bit ASCII strings as HEX literals in the SAS code.  That way the code works the same if you change the encoding setting you are running with.

 

So LOOK at the hex codes for the character by using the $HEX format.

 

Then write the code using the hexcode.

 

For example if that "box" is was just the hex code '0A'x (which is actually a linefeed) then you might use 

APPLCNT_CMT_TX=compress(APPLCNT_CMT_TX,'0A'x);

 

If the goal is to only keep normal characters then use the K modifier on the COMPRESS() function call to say that the list of characters are those that should be KEPT instead the default action of removing the listed characters.  You can use COLLATE() to generate all of the printable 7-bit ASCII characters.

APPLCNT_CMT_TX=compress(APPLCNT_CMT_TX,collate(32,126),'K');

 

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

In general I find it is better to write non 7-bit ASCII strings as HEX literals in the SAS code.  That way the code works the same if you change the encoding setting you are running with.

 

So LOOK at the hex codes for the character by using the $HEX format.

 

Then write the code using the hexcode.

 

For example if that "box" is was just the hex code '0A'x (which is actually a linefeed) then you might use 

APPLCNT_CMT_TX=compress(APPLCNT_CMT_TX,'0A'x);

 

If the goal is to only keep normal characters then use the K modifier on the COMPRESS() function call to say that the list of characters are those that should be KEPT instead the default action of removing the listed characters.  You can use COLLATE() to generate all of the printable 7-bit ASCII characters.

APPLCNT_CMT_TX=compress(APPLCNT_CMT_TX,collate(32,126),'K');

 

PaigeMiller
Diamond | Level 26

@animesh123 wrote:

Hi I want remove a bad data from a variable . so inthis obs between nicolas and 84989 there is a small icon am trying to remove that using sas in linux environment 

I tried to do the same in sas eg using 

APPLCNT_CMT_TX=compress(APPLCNT_CMT_TX,'');

this is working but in linux environement the same is now working  

 

animesh123_0-1740662700143.jpeg

 


 

 

is this a one-time need to remove just one character from this string? Or in a larger data set do possibly other characters appear depending on the string that you want to remove?

--
Paige Miller
animesh123
Obsidian | Level 7
APPLCNT_CMT_TX=compress(APPLCNT_CMT_TX,'');
want to remove only this 
Tom
Super User Tom
Super User

@animesh123 wrote:
APPLCNT_CMT_TX=compress(APPLCNT_CMT_TX,'');
want to remove only this 

And WHAT character is that exactly? 

When I try to copy and paste from your post here into SAS editor it just ends up as the '1A'x character. 

Tom_1-1740666213343.png

 

Which is just what SAS puts when it does not know how to transcode a character. 

 

If that is the actual character you have then why does this forum display it as a box with an X in it when SAS and WORD display it as just an empty box?

WORD Example: Tom_0-1740666169777.png

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1038 views
  • 0 likes
  • 3 in conversation