BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
somebody
Lapis Lazuli | Level 10

I am trying to remove special characters in variable NAME. I want a variable to flag that the name has changed so if there is such character in the NAME string, set this to 1. My question is, what would be the most efficient way to achieve this?

My code is:

data Names;
	input name & $32.;
	datalines;
		B/E Aerospace Inc 005
		A H Belo Corp12 
		A. H. BELO CORP  412
		A-H BELO CORP 125
		A - H BELO CORP 124
		;
run;
data names;set names;
	name1=compress(name,'','adk');
run;

What I want:

Name                                                  Flag
BE Aerospace Inc 005                        Yes
A H Belo Corp12                                 No
A H BELO CORP  412                        Yes
AH BELO CORP 125                          Yes
A H BELO CORP 124                         Yes
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Try removing the middle parameter:

name1 = compress(name,,'adk') ;

Then:

if lengthn(name) ne lengthn(name1) then flag=1;

View solution in original post

1 REPLY 1
Astounding
PROC Star
Try removing the middle parameter:

name1 = compress(name,,'adk') ;

Then:

if lengthn(name) ne lengthn(name1) then flag=1;

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

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 563 views
  • 3 likes
  • 2 in conversation