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

Hello

What is the way to remove all special characters

The current value is     /a/s/vvv122!!@#jfjfjf2222/-

and desired value is     asvvv122jfjfjf2222

 

data aaa;
x='/a/s/vvv122!!@#jfjfjf2222/-';
w1=compress(x, '/');/*remove / */
w2=compress(x,'','kd');/*Keeps only digits*/
w3=compress(x,"","ka");/*Keep only alphanumeric characters*/
w4=compress(x, ' ', 'A');/*Keeps only digits and special characters*/
Run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Seems like this is what you want?

 

data _null_;
    x='/a/s/vvv122!!@#jfjfjf2222/-';
    y=compress(x,'','kad');
    put y;
run;

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

Seems like this is what you want?

 

data _null_;
    x='/a/s/vvv122!!@#jfjfjf2222/-';
    y=compress(x,'','kad');
    put y;
run;
saidatta
Fluorite | Level 6

i've read ur code and then i have a doubt what if we only keep special char thanks in advance

 

Sathish_jammy
Lapis Lazuli | Level 10

 

w5=compress(x,"abcdefghijklmnopqrstuvwxyz1234567890","k");/*Keeps only digits and characters*/

If you are sure about the variable listed only character and numeric then use the given code.

Emma_at_SAS
Lapis Lazuli | Level 10
Thank you Sathish_Jammy! It was very easy to use your code!
PeterClemmensen
Tourmaline | Level 20

Alternatively

 

data _null_;
    x='/a/s/vvv122!!@#jfjfjf2222/-';
    y=prxchange('s/\W//', -1, x); 
    put y;
run;
Jagadishkatam
Amethyst | Level 16

Alternatively with perl regular expression to perform the below 4 actions

 

data aaa;
x='/a/s/vvv122!!@#jfjfjf2222/-';
w1=prxchange('s#/##',-1,x); /*remove / */
w2=prxchange('s#\D*##',-1,x);/*Keeps only digits*/
w3=prxchange('s#(\W)##i',-1,x);/*Keeps only digits*/
w4=prxchange('s#[[:alpha:]]##i',-1,x);/*Keeps only digits and special characters*/
Run;

 

 

 

 

Thanks,
Jag
Anandkvn
Lapis Lazuli | Level 10

Hi Jagadeesh

Your regular expressions solutions are very impressive please give any videos  on regx 

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
  • 7 replies
  • 32604 views
  • 9 likes
  • 7 in conversation