<?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: Macro Variable values to enclose with single quote in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765328#M242410</link>
    <description>&lt;PRE&gt;%let rep_run= closing run insurance,insurance,secondary closing run insurance,business insurance,RI_BCT;
%let new=%str(%')%qsysfunc(prxchange(s/%str(,)/%str(',')/,-1,%bquote(%upcase(&amp;amp;rep_run))))%str(%');
%put &amp;amp;=new;&lt;/PRE&gt;</description>
    <pubDate>Wed, 01 Sep 2021 12:43:02 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2021-09-01T12:43:02Z</dc:date>
    <item>
      <title>Macro Variable values to enclose with single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765288#M242389</link>
      <description>&lt;P&gt;Assume I've the macro variable as follows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let rep_run= closing run insurance,insurance,secondary closing run insurance,business insurance,RI_BCT;&lt;/PRE&gt;
&lt;P&gt;Now I want to create one new macro variable (e.g. rep_run_values )&amp;nbsp;by using the&amp;nbsp;&amp;nbsp;macro variable rep_run and I want the value to be enclosed with single quote as mentioned below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;'closing run insurance','insurance','secondary closing run insurance','business insurance','RI_BCT'&lt;/PRE&gt;
&lt;P&gt;Any help?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 10:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765288#M242389</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-09-01T10:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable values to enclose with single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765291#M242390</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rep_run= closing run insurance,insurance,secondary closing run insurance,business insurance,RI_BCT;
%let new=%unquote(%str(%')%qsysfunc(tranwrd(%superq(rep_run),%str(,),','))%str(%'));
%put &amp;amp;=new;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;405   %let rep_run= closing run insurance,insurance,secondary closing run insurance,business insurance,RI_BCT;
406   %let new=%unquote(%str(%')%qsysfunc(tranwrd(%superq(rep_run),%str(,),','))%str(%'));
407   %put &amp;amp;=new;
NEW='closing run insurance','insurance','secondary closing run insurance','business insurance','RI_BCT'

&lt;/PRE&gt;
&lt;P&gt;Convert the commas to ',' and add quotes before and after.&amp;nbsp; Once the string is quoted there is no longer any need for macro quoting.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 10:39:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765291#M242390</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-01T10:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable values to enclose with single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765293#M242391</link>
      <description>&lt;P&gt;You can use the QLIST macro&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/qlist.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/qlist.sas&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 10:44:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765293#M242391</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-01T10:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable values to enclose with single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765300#M242392</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Great! I do have one more question. How to convert the strings to upper case after enclosing it with single quote.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired result is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;'CLOSING RUN INSURANCE','INSURANCE','SECONDARY CLOSING RUN INSURANCE','BUSINESS INSURANCE','RI_BCT'&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 10:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765300#M242392</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-09-01T10:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable values to enclose with single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765301#M242393</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let new = %upcase(&amp;amp;new);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 10:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765301#M242393</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-01T10:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable values to enclose with single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765302#M242394</link>
      <description>&lt;P&gt;Just for fun, data step approach, with upcase.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rep_run= closing run insurance,insurance,secondary closing run insurance,business insurance,RI_BCT;
%put &amp;amp;=rep_run.;

data _null_;
  length text str rep_run $ 32767;
  text = symget("rep_run");

    do _N_= 1 to countw(text, ",");
      str = scan(text, _N_, ",");
      rep_run = catx(",", rep_run, quote(upcase(strip(str)),"'"));
    end;

  call symputx("rep_run", rep_run, "G");
run;

%put &amp;amp;=rep_run.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[EDIT:] If the macro variable contains special characters, e.g. % or &amp;amp;, the code works too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 11:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765302#M242394</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-09-01T11:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable values to enclose with single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765320#M242409</link>
      <description>&lt;P&gt;See also Richard DeVenezia's %seplist macro function.&amp;nbsp; It does that and a lot more.&amp;nbsp; Very handy.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.devenezia.com/downloads/sas/macros/index.php?m=seplist" target="_blank"&gt;https://www.devenezia.com/downloads/sas/macros/index.php?m=seplist&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 12:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765320#M242409</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2021-09-01T12:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable values to enclose with single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765328#M242410</link>
      <description>&lt;PRE&gt;%let rep_run= closing run insurance,insurance,secondary closing run insurance,business insurance,RI_BCT;
%let new=%str(%')%qsysfunc(prxchange(s/%str(,)/%str(',')/,-1,%bquote(%upcase(&amp;amp;rep_run))))%str(%');
%put &amp;amp;=new;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 12:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765328#M242410</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-01T12:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable values to enclose with single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765329#M242411</link>
      <description>&lt;P&gt;Note there is a %QUPCASE() function.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 12:43:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765329#M242411</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-01T12:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable values to enclose with single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765330#M242412</link>
      <description>Sure . I just realize OP need UPCASE it ,after %bquote() .</description>
      <pubDate>Wed, 01 Sep 2021 12:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765330#M242412</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-01T12:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable values to enclose with single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765336#M242417</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;If I run the code below, I could see a some blanks in the value of macro variable rprun_pi_val. How to remove the blanks?&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let rprun_pi=main close run(VFB),secondary close run,main close run(BBB),impact of overreturn on CSP,baseline for inital recognition(VFB),                    Coverage Units new business,main close run mortality,main close run longevity,main close run lapse down,secondary close run mortality,
	secondary close run longevity,secondary close run lapse down;
%let rprun_pi_val=%upcase(%unquote(%str(%')%qsysfunc(tranwrd(%superq(rprun_pi),%str(,),','))%str(%')));
%put &amp;amp;=rprun_pi_val;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;26         %let rprun_pi=main close run(VFB),secondary close run,main close run(BBB),impact of overreturn on CSP,baseline for inital
26       !  recognition(VFB),                    Coverage Units new business,main close run mortality,main close run longevity,main
26       ! close run lapse down,secondary close run mortality,
27         	secondary close run longevity,secondary close run lapse down;
28         %let rprun_pi_val=%upcase(%unquote(%str(%')%qsysfunc(tranwrd(%superq(rprun_pi),%str(,),','))%str(%')));
29         %put &amp;amp;=rprun_pi_val;
RPRUN_PI_VAL='MAIN CLOSE RUN(VFB)','SECONDARY CLOSE RUN','MAIN CLOSE RUN(BBB)','IMPACT OF OVERRETURN ON CSP','BASELINE FOR INITAL 
RECOGNITION(VFB)','                    COVERAGE UNITS NEW BUSINESS','MAIN CLOSE RUN MORTALITY','MAIN CLOSE RUN LONGEVITY','MAIN 
CLOSE RUN LAPSE DOWN','SECONDARY CLOSE RUN MORTALITY','  SECONDARY CLOSE RUN LONGEVITY','SECONDARY CLOSE RUN LAPSE DOWN'&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;26         %let rprun_pi=main close run(VFB),secondary close run,main close run(BBB),impact of overreturn on CSP,baseline for inital
26       !  recognition(VFB),                    Coverage Units new business,main close run mortality,main close run longevity,main
26       ! close run lapse down,secondary close run mortality,
27         	secondary close run longevity,secondary close run lapse down;
28         %let rprun_pi_val=%upcase(%unquote(%str(%')%qsysfunc(tranwrd(%superq(rprun_pi),%str(,),','))%str(%')));
29         %put &amp;amp;=rprun_pi_val;
RPRUN_PI_VAL='MAIN CLOSE RUN(VFB)','SECONDARY CLOSE RUN','MAIN CLOSE RUN(BBB)','IMPACT OF OVERRETURN ON CSP','BASELINE FOR INITAL RECOGNITION(VFB)','COVERAGE UNITS NEW BUSINESS','MAIN CLOSE RUN MORTALITY','MAIN CLOSE RUN LONGEVITY','MAIN 
CLOSE RUN LAPSE DOWN','SECONDARY CLOSE RUN MORTALITY','SECONDARY CLOSE RUN LONGEVITY','SECONDARY CLOSE RUN LAPSE DOWN'&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 13:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765336#M242417</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-09-01T13:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable values to enclose with single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765344#M242421</link>
      <description>&lt;PRE&gt;%let rep_run= rprun_pi=main close run(VFB),secondary close run,main close run(BBB),impact of overreturn on CSP,baseline for inital recognition(VFB),                    Coverage Units new business,main close run mortality,main close run longevity,main close run lapse down,secondary close run mortality,
	secondary close run longevity,secondary close run lapse down;

%let new=%str(%')%qsysfunc(prxchange(s/\s*%str(,)\s*/%str(',')/,-1,%qupcase(&amp;amp;rep_run)))%str(%');
%put &amp;amp;=new;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 13:19:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765344#M242421</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-01T13:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable values to enclose with single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765347#M242422</link>
      <description>&lt;P&gt;The best way is to not build the macro variable with the spaces to begin with.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rprun_pi=main close run(VFB),secondary close run,main close run(BBB);
%let rprun_pi=&amp;amp;rprun_pi,impact of overreturn on CSP,baseline for inital recognition(VFB);
%let rprun_pi=&amp;amp;rprun_pi,Coverage Units new business,main close run mortality,main close run longevity;
%let rprun_pi=&amp;amp;rprun_pi,main close run lapse down,secondary close run mortality;
%let rprun_pi=&amp;amp;rprun_pi,secondary close run longevity,secondary close run lapse down;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How did you build that original macro variable?&lt;/P&gt;
&lt;P&gt;Couldn't you build it with the quotes to start with?&amp;nbsp; For example if the list of values was in a dataset&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select quote(trim(ds_var),"'") into :mvar separated by ',' 
    from have
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are stuck with the list with extra spaces.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You could adapt the posted REGEX solution to include the spaces around the commas in the string to be replaced.&lt;/LI&gt;
&lt;LI&gt;You could use one of the posted methods that scans the original list and builds the new one.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;If you assign a macro variable with the result of %SCAN() then the leading and trailing spaces will not become part of the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rprun_pi=main close run(VFB),secondary close run,main close run(BBB),impact of overreturn on CSP,baseline for inital recognition(VFB),                    Coverage Units new business,main close run mortality,main close run longevity,main close run lapse down,secondary close run mortality,
	secondary close run longevity,secondary close run lapse down;

%macro quoteit(mvar);
%local i sep word;
%do i=1 %to %sysfunc(countw(%superq(&amp;amp;mvar),%str(,)));
  %let word=%scan(%superq(&amp;amp;mvar),&amp;amp;i,%str(,));
  %if %length(&amp;amp;word) %then %do;&amp;amp;sep.%bquote('&amp;amp;word')%let sep=,;%end;
%end;
%mend quoteit;
%let rprun_pi_val=%quoteit(rprun_pi);
%put &amp;amp;=rprun_pi_val;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 13:33:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-values-to-enclose-with-single-quote/m-p/765347#M242422</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-01T13:33:51Z</dc:date>
    </item>
  </channel>
</rss>

