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

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...

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

: 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

2 REPLIES 2
Florent
Quartz | Level 8

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;

art297
Opal | Level 21

: 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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 1218 views
  • 3 likes
  • 3 in conversation