Hi Team,
I am able to replace special characters with empty spaces in the text2 argument. However I am not able to achieve the same in the text3 argument. Can you please let us know how to use other functions/ variable names in the Perl regular expression?
data a;
input text $80.;
datalines;
The phone numberØ for Ed is (801)443-9876Ø but not until tonight.
He can be reached Øat (910)998-8762 Øtomorrow for testing purposesØ.
;
run;
data b;
set a;
text2=prxchange("s/Ø//", -1, text);
test3 = prxchange("s/byte(216)//", -1, text);
test4= byte(216);
run;
Thanks & Regards,
Bhanu Prakash Pala
Same thing.
Another way to code that:
VAR2 = prxchange('s/[^\x21-\x7E]/ /', -1, VAR);
or
VAR2 = prxchange('s/[\x00-\x1F\x7F-\xFF]/ /',-1, VAR);
I only use regular expressions for the real complex stuff.
You can get very far with these 3 SAS functions :
Thanks,
Koen
Yes, I was aware that we can achieve using those functions. I wanted to use a regular expression to achieve the requirement.
Please suggest to me if there are any other ways in the regular expressions.
If special character means anything outside of the lower ascii characters (33 to 126, i.e. ! to ~), this might help:
VAR2 = prxchange('s/[^!-~]/ /', -1, VAR);
Be careful if using UTF8 encoding.
I wanted to replace blank if we have ASCII specifically characters (1-31,127-255) in the Text. I can’t type those characters manually.
Our program should work in dynamic way.
Same thing.
Another way to code that:
VAR2 = prxchange('s/[^\x21-\x7E]/ /', -1, VAR);
or
VAR2 = prxchange('s/[\x00-\x1F\x7F-\xFF]/ /',-1, VAR);
Any ASCII table will show the list of characters. Just search that.
@bhanuprakash Given that your RegEx actually removes characters without replacing them with a blank the compress() function might also do the job for you.
To be considered for using compress():
1. compress() will perform better than RegEx which might be relevant in case you're dealing with bigger data volumes
2. The SAS RegEx functions can only get used with single byte encoded data. If your data is multibyte encoded then consider using function kcompress() with the appropriate modifiers.
data a;
input text $80.;
datalines;
The phone numberØ for Ed is (801)443-9876Ø but not until tonight.
He can be reached Øat (910)998-8762 Øtomorrow for testing purposesØ.
;
run;
data b;
set a;
text2=prxchange("s/Ø//", -1, text);
text3=prxchange('s/[\x01-\x1B\x7F-\xFF]//', -1, text);
text4=compress(text,' ','knp');
run;
proc print data=b;
run;
And to find the hex values for ASCII values just Google for ASCII Table and you'll find what you need.
Post-Factum, but may still be useful to you !
Transcoding: Understand, Troubleshoot, and Resolve a Most Mysterious SAS® Error
Posted 03-15-2021 09:43 AM | by imujulie
https://communities.sas.com/t5/SAS-Global-Forum-Proceedings/Transcoding-Understand-Troubleshoot-and-...
Koen
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.
Ready to level-up your skills? Choose your own adventure.