<?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: TRANSTR works in a datastep but does not inside %SYSFUNC() in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/TRANSTR-works-in-a-datastep-but-does-not-inside-SYSFUNC/m-p/658409#M197340</link>
    <description>Thanks for the solution. It works fine.</description>
    <pubDate>Sun, 14 Jun 2020 20:46:04 GMT</pubDate>
    <dc:creator>SPR</dc:creator>
    <dc:date>2020-06-14T20:46:04Z</dc:date>
    <item>
      <title>TRANSTR works in a datastep but does not inside %SYSFUNC()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TRANSTR-works-in-a-datastep-but-does-not-inside-SYSFUNC/m-p/658400#M197332</link>
      <description>&lt;P&gt;I have the following code that works fine. What I need is to replace commas in a=A.B,C string with asterisks to get s="A" "B" "C" string.&lt;/P&gt;
&lt;P&gt;The data step version of the code works fine:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;%let a=A,B,C;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;data a; s='"'||TRANSTRN("&amp;amp;a",",",'" "')||'"'; run;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#008000"&gt;/* dataset a:&amp;nbsp; */&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#008000"&gt;/* s&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#008000"&gt;/*"A" "B" "C"&amp;nbsp; */&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, using %SYSFUNC(TRANSTR(...)) fails or produces wrong result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%let s=%SYSFUNC(TRANSTRN(&amp;amp;a,",",'" "')); %put s=&amp;amp;s;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;/*ERROR: The function TRANSTRN referenced by the %SYSFUNC or %QSYSFUNC macro function has too many arguments.*/&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;%let s=%SYSFUNC(TRANSTRN("&amp;amp;a",",",'" "')); %put s=&amp;amp;s;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;/*s="A,B,C"*/&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;%let s=%QSYSFUNC(TRANSTRN(&amp;amp;a,",",'" "')); %put s=&amp;amp;s;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;/*ERROR: The function TRANSTRN referenced by the %SYSFUNC or %QSYSFUNC macro function has too many arguments.*/&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;Any help?&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jun 2020 20:05:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TRANSTR-works-in-a-datastep-but-does-not-inside-SYSFUNC/m-p/658400#M197332</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2020-06-14T20:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: TRANSTR works in a datastep but does not inside %SYSFUNC()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TRANSTR-works-in-a-datastep-but-does-not-inside-SYSFUNC/m-p/658404#M197335</link>
      <description>&lt;P&gt;Why are you searching for quotes in the value of the macro variable A?&amp;nbsp; There aren't any quotes in A. Your data step did not search for quotes.&lt;/P&gt;
&lt;P&gt;So in the data step you did this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;s='"'||TRANSTRN("&amp;amp;a",",",'" "')||'"';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is changing commas to a space with double quotes around it.&lt;/P&gt;
&lt;P&gt;But in the %SYSFUNC() call you did this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let s=%SYSFUNC(TRANSTRN(&amp;amp;a,",",'" "'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is changing a comma with double quotes around it to a space with double quotes around it that also has single quotes around it.&lt;/P&gt;
&lt;P&gt;You probably meant to do this instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let s=%SYSFUNC(TRANSTRN(&amp;amp;a,%str(,)," "));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also need to add macro quoting to A because it also has commas in it.&lt;/P&gt;
&lt;P&gt;Note there is no need to use TRANSTRN instead of plain old TRANWRD because you aren't converting the values to null strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let s="%SYSFUNC(TRANWRD(%superq(a),%str(,)," "))";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;13    %let a=One,Two,Three;
14    %let s="%SYSFUNC(TRANWRD(%superq(a),%str(,)," "))";
15    %put &amp;amp;=a &amp;amp;=s;
A=One,Two,Three S="One" "Two" "Three"&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Jun 2020 20:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TRANSTR-works-in-a-datastep-but-does-not-inside-SYSFUNC/m-p/658404#M197335</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-14T20:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: TRANSTR works in a datastep but does not inside %SYSFUNC()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TRANSTR-works-in-a-datastep-but-does-not-inside-SYSFUNC/m-p/658405#M197336</link>
      <description>&lt;P&gt;SAS Macro level is purely textual and though you don't need to quote text. But then because you're dealing with commas which also have a meaning on macro level you do need to macro quote these strings. Alternatively use a data _null_ step to create the macro variable. That's often easier to formulate and debug.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a=A,B,C;

/* option 1 */
%let s="%sysfunc(transtrn(%nrbquote(&amp;amp;a),%nrbquote(,)," "))";
%put &amp;amp;=s;

/* option 2 */
data _null_;
  s=cats('"',TRANSTRN("&amp;amp;a",",",'" "'),'"');
  call symputx('s',s);
  stop;
run;
%put &amp;amp;=s;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Jun 2020 20:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TRANSTR-works-in-a-datastep-but-does-not-inside-SYSFUNC/m-p/658405#M197336</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-14T20:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: TRANSTR works in a datastep but does not inside %SYSFUNC()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TRANSTR-works-in-a-datastep-but-does-not-inside-SYSFUNC/m-p/658407#M197338</link>
      <description>&lt;P&gt;Thanks for the advice, however, I've got the following result with your code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ERROR: The function TRANSTRN referenced by the %SYSFUNC or %QSYSFUNC macro function has too many arguments.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;27 %let s=%SYSFUNC(TRANSTRN(&amp;amp;a,%str(,)," ")); %put s=&amp;amp;s;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;/* s= */&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jun 2020 20:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TRANSTR-works-in-a-datastep-but-does-not-inside-SYSFUNC/m-p/658407#M197338</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2020-06-14T20:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: TRANSTR works in a datastep but does not inside %SYSFUNC()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TRANSTR-works-in-a-datastep-but-does-not-inside-SYSFUNC/m-p/658409#M197340</link>
      <description>Thanks for the solution. It works fine.</description>
      <pubDate>Sun, 14 Jun 2020 20:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TRANSTR-works-in-a-datastep-but-does-not-inside-SYSFUNC/m-p/658409#M197340</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2020-06-14T20:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: TRANSTR works in a datastep but does not inside %SYSFUNC()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TRANSTR-works-in-a-datastep-but-does-not-inside-SYSFUNC/m-p/658410#M197341</link>
      <description>&lt;P&gt;Using clues from both replies it seems to I found a shorter code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%let a=A,B,C:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%let s=%SYSFUNC(TRANSTRN("&amp;amp;a",%str(,)," ")); %put s=&amp;amp;s;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;/*s="A" "B" "C"*/&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jun 2020 21:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TRANSTR-works-in-a-datastep-but-does-not-inside-SYSFUNC/m-p/658410#M197341</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2020-06-14T21:01:39Z</dc:date>
    </item>
  </channel>
</rss>

