BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dsrountree
Obsidian | Level 7

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:

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
LinusH
Tourmaline | Level 20

Maybe tranwrd()?

Data never sleeps
ballardw
Super User

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

TRANWRD will leave a single space when attempting to delete.

Dsrountree
Obsidian | Level 7

I've never heard of TRANSTRN.

Can you provide a sample of how it functions?

Ex: TRANWRD(source,target,replacement)


ballardw
Super User

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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