Sample 24717: Remove HTML tags from character strings
The sample code on the Full Code tab illustrates how to remove HTML tags from a character string.
Note:
See also SAS Note 24719, "Remove HTML tags from a character variable value using the SUBSTR function."
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample uses Perl Regular Expressions to remove the HTML tags by searching for the minimum number of characters between and including angle brackets, "<>". The "s" at the beginning of the PRXPARSE string indicates substitution. Period is any character, asterisk means any number, the question mark makes it a minimal match, meaning the fewest number of characters. Without the "?" Perl would match everything between the first "<" and the last ">". Much more than desired.
/* Parse a pattern up to 5 bytes surrounded by < > symbols. */
/* Executing the PRXPARSE function only once and retaining its value is more efficient than executing this statement for each observation */
/* Specifying -1 as the second argument indicates to replace all matching patterns */
data a;
infile datalines truncover;
input test $char100.;
before=test;
retain rx1;
if _n_=1 then rx1=prxparse("s/<.*?>//");
call prxchange(rx1,-1,test);
datalines;
<FONT SIZE=2 FACE="Courier New">Using RX functionality</FONT>
<P><FONT SIZE=2 FACE="Courier New">Thank-you so much</FONT>
;
proc print;
var test;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Obs test
1 Using RX functionality
2 Thank-you so much
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions
|
| Date Modified: | 2020-12-08 09:37:23 |
| Date Created: | 2004-09-30 14:09:07 |
Operating System and Release Information
| SAS System | Base SAS | All | 8 TS M0 | n/a |