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

Hello,

I have some html text in one of my data sets.  I need to replace all occurrences of 'Temp' to 'Temporary'.

When I do the following it cuts the string off.

txt = tranwrd(temptext, 'Temp', 'Temporary') ;

This is my full html string

<tr>

<td>1</td>

<td>Temp 1</td>

<td>07/23/2015</td>

</tr>

<tr>

<td>2</td>

<td>Temp 4</td>

<td>03/05/2016</td>

</tr>

<tr>

<td>3</td>

<td>Temp 8</td>

<td>04/13/2017</td>

</tr>

after running the above code txt variable only has

<tr>

<td>1</td>

<td>Temp 1</td>

<td>07/23/2015</td>

</tr>

I'm not sure why this is happening.

Thank you for any help.

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

Works for me:

data _null_;

temptext='<td>Temp 1</td>  ';

txt=tranwrd(temptext, 'Temp', 'Temporary') ;

put temptext= / txt=;

run;

What is the EXACT code you used?

Update: Oh, the cut-off is probably due to the length setting of your new variable 'txt', if not specified, the default is 200. So assign a proper length before process the string.

Update2: Here is to vent a little. This is one inconsistency that I feel SAS can improve. Some functions will take the length of precessed variable (such as SUBSTR(), which I like), Some will take something else, such as this one: 200. I know this is a legacy issue resulting from different developers and is common seen in many other programming languages as well, but I still feel SAS can do better to further lift those stress put on the shoulder of programmers. Similar inconsistency also happened to TRANWRD VS TRANSLATE regarding how they align their arguments. The order differences of 'source' and 'target' makes me quit remembering. 

Haikuo

View solution in original post

2 REPLIES 2
Haikuo
Onyx | Level 15

Works for me:

data _null_;

temptext='<td>Temp 1</td>  ';

txt=tranwrd(temptext, 'Temp', 'Temporary') ;

put temptext= / txt=;

run;

What is the EXACT code you used?

Update: Oh, the cut-off is probably due to the length setting of your new variable 'txt', if not specified, the default is 200. So assign a proper length before process the string.

Update2: Here is to vent a little. This is one inconsistency that I feel SAS can improve. Some functions will take the length of precessed variable (such as SUBSTR(), which I like), Some will take something else, such as this one: 200. I know this is a legacy issue resulting from different developers and is common seen in many other programming languages as well, but I still feel SAS can do better to further lift those stress put on the shoulder of programmers. Similar inconsistency also happened to TRANWRD VS TRANSLATE regarding how they align their arguments. The order differences of 'source' and 'target' makes me quit remembering. 

Haikuo

jerry898969
Pyrite | Level 9

Hi Hai.kou,

Thank you so much.  I didn't think of adding the length statement to my code. 

That fixed it. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1755 views
  • 0 likes
  • 2 in conversation