<?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: Want to quote the string in macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492585#M129465</link>
    <description>&lt;P&gt;I assume this is for a where clause of some kind?&amp;nbsp; If so you can do it there:&lt;/P&gt;
&lt;PRE&gt;%let name=M,F; &lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt; set sashelp.class;&lt;BR /&gt; where sex in ("%sysfunc(tranwrd(%quote(&amp;amp;name.),%str(,),%str(" ")))");&lt;BR /&gt;run;&lt;/PRE&gt;</description>
    <pubDate>Wed, 05 Sep 2018 10:53:57 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-09-05T10:53:57Z</dc:date>
    <item>
      <title>Want to quote the string in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492578#M129459</link>
      <description>&lt;P&gt;%let name=AE,DM,ED,KK,OO,GG; * there could be n number of comma seprated values;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*result required;&lt;/P&gt;&lt;P&gt;String='AE','DM','ED','KK','OO','GG'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note-we have to take care that name can have min one value or max 100 comma separated values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone have any resolution.Kindly help me on the same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Ankit&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 10:21:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492578#M129459</guid>
      <dc:creator>ankitk321</dc:creator>
      <dc:date>2018-09-05T10:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Want to quote the string in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492580#M129460</link>
      <description>&lt;P&gt;I'd do it in a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
oldvar = "&amp;amp;name";
length newvar $1000;
do i = 1 to countw(oldvar,',');
  newvar = catx(',',newvar,"'"!!scan(oldvar,i,',')!!"'");
end;
call symput('newname',trim(newvar));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or you use the quote() function: &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
oldvar = "&amp;amp;name";
length newvar $1000;
do i = 1 to countw(oldvar,',');
  newvar = catx(',',newvar,quote(scan(oldvar,i,','),"'"));
end;
call symput('newname',trim(newvar));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Sep 2018 10:34:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492580#M129460</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-05T10:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: Want to quote the string in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492585#M129465</link>
      <description>&lt;P&gt;I assume this is for a where clause of some kind?&amp;nbsp; If so you can do it there:&lt;/P&gt;
&lt;PRE&gt;%let name=M,F; &lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt; set sashelp.class;&lt;BR /&gt; where sex in ("%sysfunc(tranwrd(%quote(&amp;amp;name.),%str(,),%str(" ")))");&lt;BR /&gt;run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Sep 2018 10:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492585#M129465</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-05T10:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: Want to quote the string in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492586#M129466</link>
      <description>&lt;P&gt;Assuming that there is no whitespace in the value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let name=AE,DM,ED,KK,OO,GG;

data _null_;
   length newvar $ 1000;
   newvar = cats("'", tranwrd("&amp;amp;name.", ",", "','"), "'");
   call symputx('newname', newvar);
run;

%put &amp;amp;=name;
%put &amp;amp;=newname;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: i should have reloaded the tab firefox to see that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; already posted a solution with tranwrd &lt;span class="lia-unicode-emoji" title=":neutral_face:"&gt;😐&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 10:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492586#M129466</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-09-05T10:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Want to quote the string in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492597#M129474</link>
      <description>&lt;P&gt;Richard DeVenezia has a great function-style macro utility %seplist, which is used for management of lists in the macro language.&amp;nbsp; Given a list of items, it can add quotes, or add a prefix, or change the delimiter etc.&amp;nbsp; It's really handy.&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;P&gt;e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;21   %let name=AE,DM,ED,KK,OO,GG;
22
23   %put %seplist(%superq(name),indlm=%str(,),nest=Q) ;
'AE','DM','ED','KK','OO','GG'
24   %put %seplist(%superq(name),indlm=%str(,),dlm=%str( )) ;
AE DM ED KK OO GG
25   %put %seplist(%superq(name),indlm=%str(,),prefix=_) ;
_AE,_DM,_ED,_KK,_OO,_GG
&lt;/PRE&gt;
&lt;P&gt;I changed the last line of the macro to definition to %unquote(&amp;amp;emit)&amp;nbsp; because sometimes the macro language doesn't handle unquoting properly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 11:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492597#M129474</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-09-05T11:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Want to quote the string in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492668#M129504</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp; Very nice sir. Thank you for sharing!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would you mind posting similar stuff in our community library for the benefit of wider audience plz&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 14:17:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492668#M129504</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-05T14:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: Want to quote the string in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492719#M129529</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;It's not my macro, Richard gets all the credit.&amp;nbsp; I don't think Richard is on communities.sas.com (?), but since he has it posted to his website, he's obviously happy to share.&amp;nbsp; I'm not likely to write up a post for the library any time soon.&amp;nbsp; But please, you should feel free.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or I know&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15043"&gt;@ScottBass&lt;/a&gt;&amp;nbsp;has shared a version of Richard's %seplist at&amp;nbsp;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/seplist.sas.&amp;nbsp;" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/seplist.sas.&amp;nbsp;&lt;/A&gt; Maybe Scott will write a library article on his whole macro library, including %seplist.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 16:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492719#M129529</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-09-05T16:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: Want to quote the string in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492869#M129618</link>
      <description>&lt;P&gt;Adding to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;'s comments...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a personal coding preference to never mix syntax in with my macro data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example, if my list is AE,DM,ED,KK,OO,GG, then I would always code it as:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=AE DM ED KK OO GG;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and never:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=AE,DM,ED,KK,OO,GG;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list='AE','DM','ED','KK','OO','GG';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The commas and quotes are syntax elements, not data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, what if that list is a list of column names for a keep statement?&amp;nbsp; You only want a comma-separated, quoted list because you're going to use the list in a where clause IN() operator (???)&amp;nbsp; That's syntax, dictated by the context in which the macro variable is being referenced.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If my data contains spaces, I use a different delimiter that will not be in my data; either a caret (^), tilde (~), or pipe (|) will usually work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=Hello World ^ Billy Bob ^ Peggy Sue;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, I "inject" the correct syntax into the code at run time, when the data is referenced.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=Hello World ^ Billy Bob ^ Peggy Sue;
%put %seplist(&amp;amp;list,nest=Q,indlm=^);
&lt;BR /&gt;&lt;BR /&gt;* Or a contrived example: ;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%let list=This Is My Directory Path;&lt;BR /&gt;%put %seplist(&amp;amp;list,dlm=/);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;* Using my favourite %loop macro: ;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%let list=Hello World ~ Billy Bob ~ Peggy Sue;
%macro code;
   %put &amp;amp;=word;
%mend;&lt;BR /&gt;%loop(&amp;amp;list,dlm=~);

&lt;BR /&gt;* or even: ;

%macro code;&lt;BR /&gt;   %if &amp;amp;__iter__ gt 1 %then ,;&lt;BR /&gt;"&amp;amp;word"&lt;BR /&gt;%mend;&lt;BR /&gt;%put %loop(&amp;amp;list,dlm=~);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;* Which "works", but isn't as clean as %seplist for this use case. ;&lt;BR /&gt;&lt;BR /&gt;* or for a "two-dimensional array": ;&lt;BR /&gt;&lt;BR /&gt;%let list=FOO|BAR~BAR|BLAH~BAZ|BOO;&lt;BR /&gt;%macro code;&lt;BR /&gt;   %let name=%scan(&amp;amp;word,1,|);&lt;BR /&gt;   %let value=%scan(&amp;amp;word,2,|);&lt;BR /&gt;   %put &amp;amp;name=&amp;amp;value;&lt;BR /&gt;%mend;&lt;BR /&gt;%loop(&amp;amp;list,dlm=~);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;(I don't know why the Rich Text editor is reformatting my SAS code, but I give up!)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Commas are particularly problematic in macro variables and require all sorts of quoting that is unnecessary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See my GitHub repository for the %seplist, %loop, %loop_control, and %squote macros.&amp;nbsp; Make sure to read the use cases in the macro header.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BTW, I haven't used &amp;amp;&amp;amp;&amp;amp;macrovar&amp;amp;i syntax in years...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 03:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492869#M129618</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2018-09-06T03:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Want to quote the string in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492870#M129619</link>
      <description>&lt;P&gt;very wise and thoughtful words. Hmm i didn't know many sas-l wise men are active here too. I do have a question on multiple&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&amp;amp;&amp;amp;&amp;amp; ampersands indirect referencing which I don't wanna ask here deviating from the topic but If i'm allowed to plug you gentlemen on the question, I would do so in another separate thread.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 03:13:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492870#M129619</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-06T03:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: Want to quote the string in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492902#M129626</link>
      <description>&lt;P&gt;Too true, or even put data in datasets and merge/join/select in - and thus have the full storage of a dataset, and the full actual programming language to manipulate it.&amp;nbsp; Been saying these things for ages, but its a losing fight, even SAS themselves push this type of macro list/messy macro code out as standard on all new platforms, and set bad coding practices as default (options vartype=any for instance).&amp;nbsp; If anything its getting worse.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 07:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492902#M129626</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-06T07:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: Want to quote the string in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492918#M129631</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Too true, or even put data in datasets and merge/join/select in - and thus have the full storage of a dataset, and the full actual programming language to manipulate it.&amp;nbsp; Been saying these things for ages, but its a losing fight, even SAS themselves push this type of macro list/messy macro code out as standard on all new platforms, and set bad coding practices as default (options vartype=any for instance).&amp;nbsp; If anything its getting worse.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yep.&lt;/P&gt;
&lt;P&gt;&amp;lt;sarcasm&amp;gt;"So now we got us this nice atom bomb, so let's drop it!"&amp;lt;/sarcasm&amp;gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 09:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492918#M129631</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-06T09:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Want to quote the string in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492964#M129656</link>
      <description>I'd welcome a &amp;amp;&amp;amp;&amp;amp; question in a new thread, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;.  While sometimes I've been frustrated by the balkanization caused by having so many different SAS comminuties online, it's fun to see who pops up where (e.g. saw you pop up on linked in the other day, celebrating hashman's 'new'  base sas certification : )</description>
      <pubDate>Thu, 06 Sep 2018 11:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492964#M129656</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-09-06T11:26:20Z</dc:date>
    </item>
  </channel>
</rss>

