<?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 Re: Replace blank with a specific character in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Replace-blank-with-a-specific-character/m-p/99601#M9236</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In macro code you do not need to put quotes around strings, and if you do they will be treated as part of the string.&lt;/P&gt;&lt;P&gt;So your TRANWRD function did nothing as it did not find any matches for the three character sequence, " " , that you told it to replace.&lt;/P&gt;&lt;P&gt;Use %STR( ) to represent a single space.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let tmpattachedfilename=%sysfunc(tranwrd(/mydir/&amp;amp;myfilename..csv,%str( ),));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or more simply if you want to remove the spaces then use the COMPRESS function.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let tmpattachedfilename=%sysfunc(compress(/mydir/&amp;amp;myfilename..csv,%str( )));&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 06 Feb 2013 11:57:54 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2013-02-06T11:57:54Z</dc:date>
    <item>
      <title>Replace blank with a specific character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Replace-blank-with-a-specific-character/m-p/99600#M9235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was trying to replace each occurrence of blank with a specific character.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let myfilename=aaa bbb;&lt;/P&gt;&lt;P&gt;%let tmpattachedfilename=/mydir/%sysfunc(tranwrd(&amp;amp;myfilename., " ", "")).csv;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if i run&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;tmpattachedfilename;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the result is /mydir/aaa bbb.csv&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but the blank between aaa and bbb has not been replaced.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is wrong in my code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;many thanks.&lt;/P&gt;&lt;P&gt;Antonio&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Feb 2013 11:46:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Replace-blank-with-a-specific-character/m-p/99600#M9235</guid>
      <dc:creator>garag</dc:creator>
      <dc:date>2013-02-06T11:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: Replace blank with a specific character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Replace-blank-with-a-specific-character/m-p/99601#M9236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In macro code you do not need to put quotes around strings, and if you do they will be treated as part of the string.&lt;/P&gt;&lt;P&gt;So your TRANWRD function did nothing as it did not find any matches for the three character sequence, " " , that you told it to replace.&lt;/P&gt;&lt;P&gt;Use %STR( ) to represent a single space.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let tmpattachedfilename=%sysfunc(tranwrd(/mydir/&amp;amp;myfilename..csv,%str( ),));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or more simply if you want to remove the spaces then use the COMPRESS function.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let tmpattachedfilename=%sysfunc(compress(/mydir/&amp;amp;myfilename..csv,%str( )));&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Feb 2013 11:57:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Replace-blank-with-a-specific-character/m-p/99601#M9236</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-02-06T11:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Replace blank with a specific character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Replace-blank-with-a-specific-character/m-p/99602#M9237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The compress seems works better that tranword:-)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Feb 2013 12:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Replace-blank-with-a-specific-character/m-p/99602#M9237</guid>
      <dc:creator>garag</dc:creator>
      <dc:date>2013-02-06T12:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Replace blank with a specific character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Replace-blank-with-a-specific-character/m-p/99603#M9238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The compress functions is the appropriate method in your case.&amp;nbsp; I'd personally stick with that solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's interesting that the tranwrd example does not work but the translate function seems to:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let A=/mydir/aaa bbb.csv;&lt;/P&gt;&lt;P&gt;%let B=%sysfunc(translate(&amp;amp;A, '_', ' '));&lt;/P&gt;&lt;P&gt;%put &amp;amp;B;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's a good practice to avoid using spaces in file names for files that will be inputs to computer process (i.e. data files for data analysis).&amp;nbsp; Most people use underscores instead of spaces.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tranwrd seems to work fine if used in a data step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let myfilename=/mydir/aaa bbb.csv;&lt;/P&gt;&lt;P&gt;data temp;&lt;/P&gt;&lt;P&gt;newfilename = tranwrd("&amp;amp;myfilename",' ', '_');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc print data = temp;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or this one (which is more helpful because the new file name is in a macro instead of an observation):&lt;/P&gt;&lt;P&gt;%let myfilename=aaa bbb.csv;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;call symput('myfilename', tranwrd("&amp;amp;myfilename",' ', '_'));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%put &amp;amp;myfilename;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(But here I don't think we are assigning a new value to myfilename but rather overwritting the macro itself.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A final thought is to read about the double and single quotes in SAS.&amp;nbsp; Here is a good start: &lt;A href="http://www.lexjansen.com/pharmasug/2002/proceed/techtech/tt07.pdf" title="http://www.lexjansen.com/pharmasug/2002/proceed/techtech/tt07.pdf"&gt;http://www.lexjansen.com/pharmasug/2002/proceed/techtech/tt07.pdf&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Feb 2013 14:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Replace-blank-with-a-specific-character/m-p/99603#M9238</guid>
      <dc:creator>jaredp</dc:creator>
      <dc:date>2013-02-06T14:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Replace blank with a specific character</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Replace-blank-with-a-specific-character/m-p/99604#M9239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The reason your %SYSFUNC(TRANSLATE()) call works and your %SYSFUNC(TRANWRD()) call does not is related to differences in how those two functions work.&amp;nbsp; (And in the fact that you do not use quotes in macro code to indicate that a value is string. In macro code everything is a string.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TRANSLATE converts individual characters to other individual characters.&amp;nbsp; TRANWRD replaces strings with other strings.&lt;/P&gt;&lt;P&gt;So when you use %SYSFUNC(TRANSLATE(&amp;amp;A,'_',' ')) you are telling SAS to translate single quote to single quote, space to underscore and single quote to single quote.&amp;nbsp; So any single quotes that happen to appear in your source string are not changed but the spaces are changed to underscores.&amp;nbsp; I frequently use this to allow me to specify spaces and other characters that the macro pre-processor would interpret as having special meaning without requiring me to use macro quoting functions like %STR().&amp;nbsp; It is much easier to type '%' then to type %STR( %%).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your %SYSFUNC(TRANWRD()) call doesn't work because the TRANWRD function is trying to match the full string of characters.&amp;nbsp; So when you give it ' ' it is looking for the three character sequence single quote, space, single quote.&amp;nbsp; Any other space characters that are not surrounded on both sides by single quotes will not match the search criteria.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 05:28:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Replace-blank-with-a-specific-character/m-p/99604#M9239</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-02-07T05:28:40Z</dc:date>
    </item>
  </channel>
</rss>

