DATA Step, Macro, Functions and more

find spl char in the string

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

find spl char in the string

In my dataset, I want to display those records containing special character.Also  a column should be added containing the list of spl char.

e.g.

data have;

   input id string :$100.;

  

cards;

1 Asthma!I

2 Anaphylexia@#T

3 The Government has called for the immediate release of an Irishman $$$1O

4 He is suffereinΣg from Jaund■ce

5 Film¶city looks go§d

6 The IÉnternational @l¥mpic Committee has moved to cÄlm fears

7 IV.D10W250

8 I fell in river

9 Singapore will add two new subway lines and expand three existing lines

Output should be like this

ID     string                                  specialchar

1     Asthma!I                                     !

2    Anaphylexia@#T                         @#

etc...


Accepted Solutions
Solution
‎01-17-2013 09:38 AM
PROC Star
Posts: 7,467

Re: find spl char in the string

: With compress you can specify exactly which characters to either keep or ignore.  e.g.:

data have;

  informat string $100.;

   input id string &;

  cards;

1 Asthma!I

2 Anaphylexia@#T

3 The Government has called for the immediate release of an Irishman $$$1O

4 He is suffereinΣg from Jaund■ce

5 Film¶city looks go§d

6 The IÉnternational @l¥mpic Committee has moved to cÄlm fears

7 IV.D10W250

8 I fell in river

9 Singapore will add two new subway lines and expand three existing lines

10 I'll never tell

;

data want;

  set have;

  specialchar = compress(compress(string,"'.", 'n'));

run;

View solution in original post


All Replies
Frequent Contributor
Posts: 127

Re: find spl char in the string

Using the compress I managed to retrieve the special characters, but unfortunately the 'É' and 'Ä' are not considered as special but rather as alpha...

data want;

      set have;

      specialchar = compress(compress(string, , 'a'));

run;

Solution
‎01-17-2013 09:38 AM
PROC Star
Posts: 7,467

Re: find spl char in the string

: With compress you can specify exactly which characters to either keep or ignore.  e.g.:

data have;

  informat string $100.;

   input id string &;

  cards;

1 Asthma!I

2 Anaphylexia@#T

3 The Government has called for the immediate release of an Irishman $$$1O

4 He is suffereinΣg from Jaund■ce

5 Film¶city looks go§d

6 The IÉnternational @l¥mpic Committee has moved to cÄlm fears

7 IV.D10W250

8 I fell in river

9 Singapore will add two new subway lines and expand three existing lines

10 I'll never tell

;

data want;

  set have;

  specialchar = compress(compress(string,"'.", 'n'));

run;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 254 views
  • 3 likes
  • 3 in conversation