<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic SAS string functions not returning expected result in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-string-functions-not-returning-expected-result/m-p/168121#M12915</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a string like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ABCD 0101&amp;nbsp; (only 1 space in middle)&lt;/P&gt;&lt;P&gt;I want ABCD_0101&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TRANWRD (trim("ABCD 0101")," ","_")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And also:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TRANSLATE (trim(("ABCD 0101"),"_"," ")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And the output is:ABCD0101 (both cases)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What did i do wrong?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 21 May 2014 18:43:49 GMT</pubDate>
    <dc:creator>eagles_dare13</dc:creator>
    <dc:date>2014-05-21T18:43:49Z</dc:date>
    <item>
      <title>SAS string functions not returning expected result</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-string-functions-not-returning-expected-result/m-p/168121#M12915</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a string like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ABCD 0101&amp;nbsp; (only 1 space in middle)&lt;/P&gt;&lt;P&gt;I want ABCD_0101&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TRANWRD (trim("ABCD 0101")," ","_")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And also:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TRANSLATE (trim(("ABCD 0101"),"_"," ")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And the output is:ABCD0101 (both cases)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What did i do wrong?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 May 2014 18:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-string-functions-not-returning-expected-result/m-p/168121#M12915</guid>
      <dc:creator>eagles_dare13</dc:creator>
      <dc:date>2014-05-21T18:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS string functions not returning expected result</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-string-functions-not-returning-expected-result/m-p/168122#M12916</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Eagles,&lt;/P&gt;&lt;P&gt;The to and from locations are not always the same in every function. The only difference I see in our code is the "trim" function and I placed my translate result into a new variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;9445&amp;nbsp; data _null;&lt;BR /&gt;9446&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RSK_SEG_ID = 'ABCD 0101';&lt;BR /&gt;9447&amp;nbsp;&amp;nbsp; rsk_seg_id_trans = translate(rsk_seg_id,'_',' ');&lt;BR /&gt;9448&amp;nbsp;&amp;nbsp; put rsk_seg_id = rsk_seg_id_trans=;&lt;BR /&gt;9449&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;RSK_SEG_ID=ABCD 0101 rsk_seg_id_trans=ABCD_0101&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;also:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;9477&lt;/P&gt;&lt;P&gt;9478 data _null;&lt;/P&gt;&lt;P&gt;9479 RSK_SEG_ID = ' ABCD 0101 ';&lt;/P&gt;&lt;P&gt;9480 rsk_seg_id_trans = translate(rsk_seg_id,'_',' ');&lt;/P&gt;&lt;P&gt;9481 rsk_seg_id_trans2 = translate(trim(left(rsk_seg_id)),'_',' ');&lt;/P&gt;&lt;P&gt;9482 rsk_seg_id_trans3 = translate(' ABCD 0101 ','_',' ');&lt;/P&gt;&lt;P&gt;9483 rsk_seg_id_trans4 = translate(trim(left(' ABCD 0101 ')),'_',' ');&lt;/P&gt;&lt;P&gt;9484 put rsk_seg_id = rsk_seg_id_trans= rsk_seg_id_trans2= rsk_seg_id_trans3= rsk_seg_id_trans4=;&lt;/P&gt;&lt;P&gt;9485 run;&lt;/P&gt;&lt;P&gt;RSK_SEG_ID=ABCD 0101 rsk_seg_id_trans=__ABCD_0101__ rsk_seg_id_trans2=ABCD_0101 rsk_seg_id_trans3=__ABCD_0101__&lt;/P&gt;&lt;P&gt;rsk_seg_id_trans4=ABCD_0101&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: James Willis. I added spaces before and after and I added the trim(left()) functions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 May 2014 18:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-string-functions-not-returning-expected-result/m-p/168122#M12916</guid>
      <dc:creator>jwillis</dc:creator>
      <dc:date>2014-05-21T18:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: SAS string functions not returning expected result</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-string-functions-not-returning-expected-result/m-p/168123#M12917</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The code you've posted has two parentheses after TRIM in the TRANSLATE example, which will result in a syntax error. It's very important to always check the log!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Other than that, your TRANSLATE example should work perfectly; in this use case, TRANSLATE is more appropriate than TRANWRD.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's the example that worked for me:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;SourceString = "ABCD 0101";&lt;/P&gt;&lt;P&gt;TargetString = TRANSLATE (trim("ABCD 0101"),"_"," ");&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 May 2014 19:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-string-functions-not-returning-expected-result/m-p/168123#M12917</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2014-05-21T19:39:12Z</dc:date>
    </item>
  </channel>
</rss>

