🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 09-04-2019 02:05 AM
(36533 views)
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Seems like this is what you want?
data _null_;
x='/a/s/vvv122!!@#jfjfjf2222/-';
y=compress(x,'','kad');
put y;
run;
7 REPLIES 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Seems like this is what you want?
data _null_;
x='/a/s/vvv122!!@#jfjfjf2222/-';
y=compress(x,'','kad');
put y;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
i've read ur code and then i have a doubt what if we only keep special char thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Sathish_Jammy! It was very easy to use your code!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Alternatively
data _null_;
x='/a/s/vvv122!!@#jfjfjf2222/-';
y=prxchange('s/\W//', -1, x);
put y;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jagadeesh
Your regular expressions solutions are very impressive please give any videos on regx