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

Dear all,

 

How can I find all the special characters? and split the special character in a new variable?

for example 

 

for JUICE∫app$le,

I expect to get 

old specialnew   
JUICE∫app$leJUICE app le
JUICE∫app$le$JUICE app le

data have ;
  infile datalines truncover;
  input name $100.;
  datalines;
JUICE∫app$le
juice <BR> apple 
juice, 'apple' 
juice{BODY} ap¶ple 
[BR]juice apple
<figure> "juice" LTD 
;
run;

 

(Special characters are characters that are not part of the following set of letters, digits and punctuation characters: A-Z; 0-9; “-“; “+”; “’”; “””; “#”; “*”; “@”; “!”; “?”; “/”; “&”; “(“; “)”; “:”; “;”; “,”; “.”; “ “.)

 

Could you please give me some suggestions about this?

thanks in advance 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data want;
   format old special new;
   set have;
   RegExID = prxparse('/[^A-Z|a-z|0-9|-|\+|’|”|#|\*|@|!|\?|\/|&|\(|\)|:|;|,|.]/');
   start=1;
   call prxnext(RegExID, start, length(old), old, pos, length);
   new=prxchange('s/[^A-Z|a-z|0-9|-|\+|’|”|#|\*|@|!|\?|\/|&|\(|\)|:|;|,|.]/ /', -1, old);
      do while (pos > 0);
         special = substr(old, pos, length);
         output;
         call prxnext(RegExID, start, length(old), old, pos, length);
      end;
   keep old special new;
run;

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

You could use the FINDC function, with modifiers "A", "K", "D", and the character list would be the punctuation you don't want to find as shown in your message.

 

https://documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=lefunctionsref&docsetTarget=n...

--
Paige Miller
andreas_lds
Jade | Level 19

You could use compress function twice to get both strings. Try:

data want;
    set have;
    
    length special new $ 100 specialChars $ 20;
    retain specialChars;
    drop specialChars;
    
    if _N_ = 1 then do;
        specialChars = cat('-+#*@!?/&():;,. "', "'");
    end;
    
    special = compress(name, specialChars, 'adik');
    new = compress(name, specialChars, 'adi');
run;
PeterClemmensen
Tourmaline | Level 20
data want;
   format old special new;
   set have;
   RegExID = prxparse('/[^A-Z|a-z|0-9|-|\+|’|”|#|\*|@|!|\?|\/|&|\(|\)|:|;|,|.]/');
   start=1;
   call prxnext(RegExID, start, length(old), old, pos, length);
   new=prxchange('s/[^A-Z|a-z|0-9|-|\+|’|”|#|\*|@|!|\?|\/|&|\(|\)|:|;|,|.]/ /', -1, old);
      do while (pos > 0);
         special = substr(old, pos, length);
         output;
         call prxnext(RegExID, start, length(old), old, pos, length);
      end;
   keep old special new;
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
  • 3 replies
  • 2598 views
  • 2 likes
  • 4 in conversation