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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 1043 views
  • 3 likes
  • 3 in conversation