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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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