<?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 multiple quotes with single quote in a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735470#M229124</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;I tried your code with different values and with different number of quotes and the result is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;26         %let var='''''''1234''''''';
27         %let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
28         %put &amp;amp;=var;
VAR=1234
29         
30         
31         %let var='''''0401''''';
32         %let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
33         %put &amp;amp;=var;
VAR=0401
34         
35         
36         %let var=''5678'';
                    __
                    49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.  Inserting white space 
             between a quoted string and the succeeding identifier is recommended.

37         %let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
38         %put &amp;amp;=var;
VAR=5678
39         
40         %let var='1111';
41         %let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
42         %put &amp;amp;=var;
VAR=1111&lt;/PRE&gt;
&lt;P&gt;Program which I ran is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let var='''''''1234''''''';
%let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
%put &amp;amp;=var;


%let var='''''0401''''';
%let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
%put &amp;amp;=var;


%let var=''5678'';
%let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
%put &amp;amp;=var;

%let var='1111';
%let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
%put &amp;amp;=var;&lt;/PRE&gt;
&lt;P&gt;Desired result is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;VAR='1234'
VAR='0401'
VAR='5678'
VAR='1111'&lt;/PRE&gt;</description>
    <pubDate>Tue, 20 Apr 2021 09:46:07 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2021-04-20T09:46:07Z</dc:date>
    <item>
      <title>Replace multiple quotes with single quote in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735452#M229112</link>
      <description>&lt;P&gt;I've one macro macro variable which is resolves to ''''''0001'''''' as you see in log below. I'm not using any single quote&amp;nbsp;or double quotes while calling&amp;nbsp;that macro variable.&amp;nbsp;Can someone guide me to&amp;nbsp;tackle this siutation by replacing multiple quotes with single quote? If I do so, then I believe this error can be elimninated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: All variables in array list must be the same type, i.e., all numeric or character.
MPRINT(TEST):   if scan(line, 5, " ", 'm') not in (''''''0001'''''') then error = error * 45;
NOTE: Line generated by the macro function "SYSFUNC".
4157       ''''''0001''''''
&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Apr 2021 08:48:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735452#M229112</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-04-20T08:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Replace multiple quotes with single quote in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735458#M229114</link>
      <description>&lt;P&gt;How the macro variable is created?&lt;/P&gt;
&lt;P&gt;B.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 08:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735458#M229114</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-04-20T08:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Replace multiple quotes with single quote in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735459#M229115</link>
      <description>&lt;P&gt;If possible resolve the issue at the source. How do you create and populate this macro var?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But here you go&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var='''''''abc''''''';
%let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
%put &amp;amp;=var;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Apr 2021 09:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735459#M229115</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-20T09:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Replace multiple quotes with single quote in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735466#M229120</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;I'm creating the macro variable as you see below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let id=0013;
%let id=%sysfunc(tranwrd(%bquote('&amp;amp;id.'),%str(,),',')); 
%put &amp;amp;id.;
&lt;/PRE&gt;
&lt;P&gt;and I'm calling it like &lt;STRONG&gt;&amp;amp;id.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 09:39:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735466#M229120</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-04-20T09:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: Replace multiple quotes with single quote in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735467#M229121</link>
      <description>&lt;P&gt;If you run it like that how do you get those multiple quotes?&lt;/P&gt;
&lt;P&gt;My log is:&lt;/P&gt;
&lt;PRE&gt;1    %let id=0013;
2    %let id=%sysfunc(tranwrd(%bquote('&amp;amp;id.'),%str(,),','));
3    %put &amp;amp;id.;
'0013'
4    %let id=0013,0017;
5    %let id=%sysfunc(tranwrd(%bquote('&amp;amp;id.'),%str(,),','));
6    %put &amp;amp;id.;
'0013','0017'
7    %let id=0013,0017,0042;
8    %let id=%sysfunc(tranwrd(%bquote('&amp;amp;id.'),%str(,),','));
9    %put &amp;amp;id.;
'0013','0017','0042'
&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 09:43:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735467#M229121</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-04-20T09:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: Replace multiple quotes with single quote in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735469#M229123</link>
      <description>&lt;P&gt;You are doing something in the macro that adds the quotes; they don't appear magically out of nothing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let id=0013;
%let id=%sysfunc(tranwrd(%bquote('&amp;amp;id.'),%str(,),',')); 
%put &amp;amp;id.;

%macro check(in);
data check;
x1 = &amp;amp;id.;
run;
%mend;

%check(&amp;amp;id.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW, in about 99% of cases, quotes in macro variables are not needed and cause only unnecessary work. I suggest you review your code design.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 09:45:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735469#M229123</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-20T09:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: Replace multiple quotes with single quote in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735470#M229124</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;I tried your code with different values and with different number of quotes and the result is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;26         %let var='''''''1234''''''';
27         %let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
28         %put &amp;amp;=var;
VAR=1234
29         
30         
31         %let var='''''0401''''';
32         %let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
33         %put &amp;amp;=var;
VAR=0401
34         
35         
36         %let var=''5678'';
                    __
                    49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.  Inserting white space 
             between a quoted string and the succeeding identifier is recommended.

37         %let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
38         %put &amp;amp;=var;
VAR=5678
39         
40         %let var='1111';
41         %let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
42         %put &amp;amp;=var;
VAR=1111&lt;/PRE&gt;
&lt;P&gt;Program which I ran is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let var='''''''1234''''''';
%let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
%put &amp;amp;=var;


%let var='''''0401''''';
%let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
%put &amp;amp;=var;


%let var=''5678'';
%let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
%put &amp;amp;=var;

%let var='1111';
%let var=%sysfunc(prxchange(s/%nrbquote(')+//,-1,%nrbquote(&amp;amp;var)));
%put &amp;amp;=var;&lt;/PRE&gt;
&lt;P&gt;Desired result is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;VAR='1234'
VAR='0401'
VAR='5678'
VAR='1111'&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Apr 2021 09:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735470#M229124</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-04-20T09:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Replace multiple quotes with single quote in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735474#M229125</link>
      <description>&lt;P&gt;Use a data step instead. That's easier to read and "safer".&amp;nbsp; ....but much better fix the issue at the source so that you never end-up with that many quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var=%nrbquote(''5678'');
data _null_;
  var=symget("var");
  var=compress(var,"'");
  call symputx('var',cats("'",var,"'"));
  stop;
run;
%put %nrbquote(&amp;amp;var);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Apr 2021 10:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735474#M229125</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-20T10:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Replace multiple quotes with single quote in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735582#M229150</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;I'm creating the macro variable as you see below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let id=0013;
%let id=%sysfunc(tranwrd(%bquote('&amp;amp;id.'),%str(,),',')); 
%put &amp;amp;id.;
&lt;/PRE&gt;
&lt;P&gt;and I'm calling it like &lt;STRONG&gt;&amp;amp;id.&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That places one set of single quotes around the value. What are you doing that manages to place multiple sets? Are you calling the&lt;/P&gt;
&lt;P&gt;%let id=%sysfunc(tranwrd(%bquote('&amp;amp;id.'),%str(,),','));&lt;/P&gt;
&lt;P&gt;portion multiple times without resetting ID to the base value?&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;1    %let id=0013;
2    %let id=%sysfunc(tranwrd(%bquote('&amp;amp;id.'),%str(,),','));
3    %put &amp;amp;id.;
'0013'
4    %let id=0013;
5    %let id=%sysfunc(tranwrd(%bquote('&amp;amp;id.'),%str(,),','));
6    %put First time: &amp;amp;id.;
First time: '0013'
7
8    %let id=%sysfunc(tranwrd(%bquote('&amp;amp;id.'),%str(,),','));
NOTE: Line generated by the macro function "SYSFUNC".
1    ''0013''
     --
     49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS
             release.  Inserting white space between a quoted string and the succeeding
             identifier is recommended.

9    %put Second time: &amp;amp;id.;
NOTE: Line generated by the macro variable "ID".
1     ''0013''
      --
      49
Second time: ''0013''
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS
             release.  Inserting white space between a quoted string and the succeeding
             identifier is recommended.

10
11   %let id=%sysfunc(tranwrd(%bquote('&amp;amp;id.'),%str(,),','));
12   %put Third time: &amp;amp;id.;
Third time: '''0013'''
&lt;/PRE&gt;
&lt;P&gt;So it appears that you have a loop that is calling your %let id=%sysfunc(tranwrd(%bquote('&amp;amp;id.'),%str(,),',')); multiple times.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Don't do that&lt;/STRONG&gt; and you extra quotes likely go away.&lt;/P&gt;
&lt;P&gt;Or reset the initial value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 14:37:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735582#M229150</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-20T14:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: Replace multiple quotes with single quote in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735702#M229180</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;I'm creating the macro variable as you see below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let id=0013;
%let id=%sysfunc(tranwrd(%bquote('&amp;amp;id.'),%str(,),',')); 
%put &amp;amp;id.;
&lt;/PRE&gt;
&lt;P&gt;and I'm calling it like &lt;STRONG&gt;&amp;amp;id.&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First thing to do is not overwrite your input macro variable with the modified value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=0013,0014;
%let qlist=%sysfunc(tranwrd(%bquote('&amp;amp;list'),%str(,),','));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really feel a need to overwrite the unquoted variable with the quoted version the first remove any quotes.&lt;/P&gt;
&lt;PRE&gt;2334  %let id='0013';
2335  %let id=%sysfunc(tranwrd(%bquote('%qsysfunc(dequote(&amp;amp;id))'),%str(,),','));
2336  %put &amp;amp;=id;
ID='0013'
&lt;/PRE&gt;
&lt;P&gt;Now you won't end up with strings like &lt;FONT face="courier new,courier"&gt;'''0013'''&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 17:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-multiple-quotes-with-single-quote-in-a-macro-variable/m-p/735702#M229180</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-20T17:55:33Z</dc:date>
    </item>
  </channel>
</rss>

