<?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: add double quotes for words in string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/435244#M108103</link>
    <description>&lt;P&gt;I'm a big fan of Richard DeVenezia's utility macro %SepList.&amp;nbsp; It does a lot of list management, including adding quotes to items, changing delimiters, adding prefixes...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;83   %let list_have = word1 word2 word3 ;
84
85   %put %seplist(&amp;amp;list_have,indlm=%str( ),dlm=%str( ),nest=QQ) ;
"word1" "word2" "word3"
86
87   %put %seplist(&amp;amp;list_have,indlm=%str( ),dlm=%str( ),nest=Q) ;
'word1' 'word2' 'word3'
88
89   %put %seplist(&amp;amp;list_have,indlm=%str( ),dlm=|) ;
word1|word2|word3
90
91   %put %seplist(&amp;amp;list_have,indlm=%str( ),dlm=%str(, ),prefix=_) ;
_word1, _word2, _word3
&lt;/PRE&gt;
&lt;P&gt;I changed my personal version slightly, so that it %unquotes the value returned, and the default value for DLM is set to INDLM.&lt;/P&gt;</description>
    <pubDate>Thu, 08 Feb 2018 13:29:01 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2018-02-08T13:29:01Z</dc:date>
    <item>
      <title>add double quotes for words in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/434809#M107947</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have got a list of words and I would like get these&amp;nbsp;words with double quotes.&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; list_have = word1 word2 word3 ...; the max number of word is 10&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I would like to get the macro variable list_want that would contain &amp;nbsp;"word1" "word2"&amp;nbsp;"word3" ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance for your help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nasser&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 11:06:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/434809#M107947</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2018-02-07T11:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: add double quotes for words in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/434813#M107949</link>
      <description>&lt;P&gt;Really not the best idea to be using a text find and replace system for data.&amp;nbsp; You can do it simply (shows the power of using the real programming language rather than find/replace) in a data _null_;&lt;/P&gt;
&lt;PRE&gt;%let list_have = word1 word2 word3;&lt;BR /&gt;
data _null_;
  length temp $2000;
  temp=cat('"',tranwrd("&amp;amp;list_have."," ",'" "'),'"');
  call symput('list_want',temp);
run;&lt;BR /&gt;
%put &amp;amp;list_want.;&lt;/PRE&gt;
&lt;P&gt;You can likely do the same if you create some ghastly complex macro code which is indecipherable and falls over every other run.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 11:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/434813#M107949</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-07T11:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: add double quotes for words in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/434814#M107950</link>
      <description>&lt;P&gt;Within a macro you can also use the following which allows direct assignment in a let statement.&amp;nbsp; &amp;nbsp; This is adapted from&amp;nbsp;&lt;A href="http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1n2i0ewaj1zian1ria5579z1zjh.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1n2i0ewaj1zian1ria5579z1zjh.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list_have = word1 word2 word3;

%macro quotelist(varlist);
   %let word_cnt=%sysfunc(countw(&amp;amp;varlist)); 
   %let list=;
   %do i = 1 %to &amp;amp;word_cnt; 
     %let temp=%qscan(%bquote(&amp;amp;varlist),&amp;amp;i);
     %let list = &amp;amp;list %bquote("&amp;amp;temp.");
   %end;
   &amp;amp;list;
%mend;

%let new = %quotelist(&amp;amp;list_have);

%put &amp;amp;=new;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Feb 2018 11:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/434814#M107950</guid>
      <dc:creator>foobarbaz</dc:creator>
      <dc:date>2018-02-07T11:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: add double quotes for words in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/434815#M107951</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list_have=word1 word2 word3;
%let want="%sysfunc(tranwrd(&amp;amp;list_have.,%str( ),%str(%" %")))";

%put &amp;amp;want.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Feb 2018 11:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/434815#M107951</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-02-07T11:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: add double quotes for words in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/434931#M107987</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/110618"&gt;@foobarbaz&lt;/a&gt;&amp;nbsp;I reached a similar result. However note the difference in behavior with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro addquote (wordlist);
/* word list is expected to be space delimited and no word containing
quotes or special symbols*/
%let result=;
%do i=1 %to %sysfunc(countw(&amp;amp;wordlist));
   %let result = &amp;amp;result %sysfunc(quote(%sysfunc(scan(&amp;amp;wordlist,&amp;amp;i))));
%end;
&amp;amp;result
%mend;

%put %addquote(var1 var2 var3);

data junk;
   set sashelp.class;
   where name in (%addquote(Alice Carol John Philip));
run;&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data junk;
   set sashelp.class;
   where name in (%quotelist(Alice Carol John Philip));
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Feb 2018 16:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/434931#M107987</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-07T16:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: add double quotes for words in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/435240#M108099</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list_have = word1 word2 word3;
%let list="%sysfunc(prxchange(s/\s+/" "/,-1,&amp;amp;list_have))";

%put &amp;amp;list ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Feb 2018 13:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/435240#M108099</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-02-08T13:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: add double quotes for words in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/435244#M108103</link>
      <description>&lt;P&gt;I'm a big fan of Richard DeVenezia's utility macro %SepList.&amp;nbsp; It does a lot of list management, including adding quotes to items, changing delimiters, adding prefixes...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;83   %let list_have = word1 word2 word3 ;
84
85   %put %seplist(&amp;amp;list_have,indlm=%str( ),dlm=%str( ),nest=QQ) ;
"word1" "word2" "word3"
86
87   %put %seplist(&amp;amp;list_have,indlm=%str( ),dlm=%str( ),nest=Q) ;
'word1' 'word2' 'word3'
88
89   %put %seplist(&amp;amp;list_have,indlm=%str( ),dlm=|) ;
word1|word2|word3
90
91   %put %seplist(&amp;amp;list_have,indlm=%str( ),dlm=%str(, ),prefix=_) ;
_word1, _word2, _word3
&lt;/PRE&gt;
&lt;P&gt;I changed my personal version slightly, so that it %unquotes the value returned, and the default value for DLM is set to INDLM.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 13:29:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/435244#M108103</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-02-08T13:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: add double quotes for words in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/435252#M108108</link>
      <description>&lt;P&gt;I am big fan of PRXCHANGE for this kind of problem which is origined from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 68         
 69         %let list_have = word1 word2 word3;
 70         %let list="%sysfunc(prxchange(s/\s+/" "/,-1,&amp;amp;list_have))";
 71         %put &amp;amp;list ;
 "word1" "word2" "word3"
 72         
 73         
 74         %let list_have = word1 word2 word3;
 75         %let list=%bquote('%sysfunc(prxchange(s/\s+/' '/,-1,&amp;amp;list_have))');
 76         %put &amp;amp;list ;
 'word1' 'word2' 'word3'
 77         
 78         
 79         %let list_have = word1 word2 word3;
 80         %let list=%sysfunc(prxchange(s/\s+/|/,-1,&amp;amp;list_have));
 81         %put &amp;amp;list ;
 word1|word2|word3
 82         
 83         %let list_have = word1 word2 word3;
 84         %let list=%sysfunc(prxchange(s/(\w+)/_$1%str(,)/,-1,&amp;amp;list_have));
 85         %put &amp;amp;list ;
 _word1, _word2, _word3,
 86         
 87         
 88         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 99         &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Feb 2018 13:45:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-double-quotes-for-words-in-string/m-p/435252#M108108</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-02-08T13:45:01Z</dc:date>
    </item>
  </channel>
</rss>

