DATA Step, Macro, Functions and more

Compress or Strip

Accepted Solution Solved
Reply
Contributor
Posts: 59
Accepted Solution

Compress or Strip

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:


Accepted Solutions
Solution
‎10-03-2013 10:48 AM
Super User
Posts: 11,343

Re: Compress or Strip

Posted in reply to Dsrountree

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;

View solution in original post


All Replies
Super User
Posts: 5,441

Re: Compress or Strip

Posted in reply to Dsrountree

Maybe tranwrd()?

Data never sleeps
Super User
Posts: 11,343

Re: Compress or Strip

Posted in reply to Dsrountree

You may actually want TRANSTRN as it replaces complete specified substring.

TRANWRD will leave a single space when attempting to delete.

Contributor
Posts: 59

Re: Compress or Strip

I've never heard of TRANSTRN.

Can you provide a sample of how it functions?

Ex: TRANWRD(source,target,replacement)


Solution
‎10-03-2013 10:48 AM
Super User
Posts: 11,343

Re: Compress or Strip

Posted in reply to Dsrountree

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;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 449 views
  • 10 likes
  • 3 in conversation