PROC SQL
CREATE TABLE WORK.PLAN AS
SELECT T1.BENEFIT,
(COMPRESS(T1.BENEFIT, '<B>')) AS NBENEFIT,
FROM WORK.PLANSVC T1;
QUIT;
T1.BENEFIT = <b>$0</b> copay B
NBENEFIT = $0/ copay.
I need a function to strip away the following:
<b>
</b>
<ul>
</ul>
<li>
</li>
When using COMPRESS it takes all the values including the B and removes it. I only want the HTML language removed from my text.
I simplified the proc sql for posting purposes, but when I extended the COMPRESS it removed "b, /, u, l, i, <, >" from all of my data.
My end results should have removed the <b> and the </b> without removing the B
I am new to SAS by the way.........:smileyconfused:
Syntax is the same: TRANSTRN(source,target,replacement)
With the same limitation one source, one target and one replacement string per call.
Your example would require a separate call for each of:
<b>
</b>
<ul>
</ul>
<li>
</li>
I don't work with trying to read HTML so I'm not sure of a better way. I suspect though you'd be better off doing this in a data step
data work.plan;
set work.plansvc (keep=benefit);
benefit = transtrn(benefit, '<b>',''); /* that is 2 single quotes not a double quote*/
benefit = transtrn(benefit, '</b>','');
continue with each replacement.
IF you have a lot of variables then use an array;
data work.plan;
set work.plansvc ;
array v <list variables to process here>;
do i = 1 to dim (v);
v = transtrn(v,'<b>','');
v = transtrn(v,'</b>','');
<continue>
end;
drop i;
run;
Maybe tranwrd()?
You may actually want TRANSTRN as it replaces complete specified substring.
TRANWRD will leave a single space when attempting to delete.
I've never heard of TRANSTRN.
Can you provide a sample of how it functions?
Ex: TRANWRD(source,target,replacement)
Syntax is the same: TRANSTRN(source,target,replacement)
With the same limitation one source, one target and one replacement string per call.
Your example would require a separate call for each of:
<b>
</b>
<ul>
</ul>
<li>
</li>
I don't work with trying to read HTML so I'm not sure of a better way. I suspect though you'd be better off doing this in a data step
data work.plan;
set work.plansvc (keep=benefit);
benefit = transtrn(benefit, '<b>',''); /* that is 2 single quotes not a double quote*/
benefit = transtrn(benefit, '</b>','');
continue with each replacement.
IF you have a lot of variables then use an array;
data work.plan;
set work.plansvc ;
array v <list variables to process here>;
do i = 1 to dim (v);
v = transtrn(v,'<b>','');
v = transtrn(v,'</b>','');
<continue>
end;
drop i;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.