Sample 24719: Remove HTML tags from a character variable value using the SUBSTR function
Using an iterative do loop, create a new variable that
contains the original variable value but no text between
the bytes < and >. The bytes < and > will not be included in
the new variable.
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.
data out;
length text final $ 70;
retain outflag 1 spaceflag 0;
input text $70.;
do i = 1 to length(text);
if substr(text,i,1) eq "<" then outflag = 0;
if substr(text,i,1) eq " " then spaceflag = 1;
if outflag = 1 then do;
if i GT 1 and substr(text,i-1,1) eq " " then
final = trim(final)||' '||substr(text,i,1);
else final = trim(final)||substr(text,i,1);
end;
if outflag = 0 and substr(text,i,1) eq ">" then outflag = 1;
end;
keep final;
datalines4;
<!-- include HEADER end --> This should not be removed <this should>
<pre>
/* create sample data set */
data one;
do i=1 to 10;
output;
end;
run;
</pre>
</td>
<!-- include FOOTER begin -->
<tr bgcolor="#FFCC33">
<td height="20" colspan="4" valign="bottom"><center>
<span class="yllwbar">
;;;;
proc print;
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 final
1 This should not be removed
2
3 /* create sample data set */
4 data one;
5 do i=1 to 10;
6 output;
7 end;
8 run;
9
10
11
12
13
14
Using an iterative DO loop, create a new variable that
contains the original variable value but no text between
the bytes < and >. The bytes < and > will not be included in
the new variable.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions ==> Character
|
| Date Modified: | 2005-12-16 03:02:57 |
| Date Created: | 2004-09-30 14:09:07 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |