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.
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
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
Hi Hai.kou,
Thank you so much. I didn't think of adding the length statement to my code.
That fixed it.
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.
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.