<?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: A confusion about macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901659#M356322</link>
    <description>Thank you very much for your patience and clear guidance！</description>
    <pubDate>Mon, 06 Nov 2023 01:23:59 GMT</pubDate>
    <dc:creator>duanzongran</dc:creator>
    <dc:date>2023-11-06T01:23:59Z</dc:date>
    <item>
      <title>A confusion about macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901346#M356220</link>
      <description>&lt;P&gt;dear all:&lt;BR /&gt;I want to write the macro variable a into datasets ,the code is :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*here a is a weird string,below is a example;
%let a="hello","world!";
data test;
x="'"||%nrstr(&amp;amp;a.)||"'";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but this is failed ,the log shows :&lt;/P&gt;
&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant,&lt;BR /&gt;a datetime constant, a missing value, arrayname, (, +, -, INPUT, NOT, PUT, ^, _NEW_, ~.&lt;/P&gt;
&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;the expected result is :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_want;
x_want='"hello","world!"';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How can I make the code work? OR a better way to write the weird string to dataset?&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2023 09:42:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901346#M356220</guid>
      <dc:creator>duanzongran</dc:creator>
      <dc:date>2023-11-03T09:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: A confusion about macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901347#M356221</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
x="%bquote(&amp;amp;a.)";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to use quoting functions to handle a macro variable like &amp;amp;A which contains special characters, in this case the comma is the problem. You need double quotes around the macro function in order to have SAS recognize the results as a character string.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2023 09:56:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901347#M356221</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-03T09:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: A confusion about macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901359#M356224</link>
      <description>&lt;P&gt;Use the SYMGET function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x = quote(symget("a"),'");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Nov 2023 10:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901359#M356224</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-11-03T10:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: A confusion about macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901414#M356240</link>
      <description>&lt;P&gt;What value do you want to put into the dataset variable?&lt;/P&gt;
&lt;P&gt;Do you just want the value that is in the macro variable?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x = symget('a');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you want store the quoted value instead?&amp;nbsp; Then don't just append quotes, use the QUOTE() function as it will properly double up any embedded quotes.&lt;/P&gt;
&lt;PRE&gt;419  %let a="hello","world!";
420  data test;
421    x=quote(symget('a'));
422    y=quote(symget('a'),"'");
423    put x= / y=;
424  run;

x="""hello"",""world!"""
y='"hello","world!"'
&lt;/PRE&gt;
&lt;P&gt;Or do you want all of the individually quotes words in your macro variable?&amp;nbsp; if the value is as nice as your example use it to generate a DO loop.&lt;/P&gt;
&lt;PRE&gt;426  %let a="hello","world!";
427  data test;
428    length x $50;
429    do x=&amp;amp;a;
430      put x=;
431      output;
432    end;
433  run;

x=hello
x=world!
NOTE: The data set WORK.TEST has 2 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Nov 2023 15:07:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901414#M356240</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-03T15:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: A confusion about macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901659#M356322</link>
      <description>Thank you very much for your patience and clear guidance！</description>
      <pubDate>Mon, 06 Nov 2023 01:23:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901659#M356322</guid>
      <dc:creator>duanzongran</dc:creator>
      <dc:date>2023-11-06T01:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: A confusion about macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901660#M356323</link>
      <description>&lt;P&gt;Thank you sir！&lt;/P&gt;
&lt;P&gt;I guess&amp;nbsp; below is what you want to tell me：&lt;/P&gt;
&lt;PRE&gt;x = quote(symget("a"),"'");&lt;/PRE&gt;
&lt;P&gt;I didn't expect it to be so difficult to control the output of single and double quotes in SAS！&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2023 02:13:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901660#M356323</guid>
      <dc:creator>duanzongran</dc:creator>
      <dc:date>2023-11-06T02:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: A confusion about macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901661#M356324</link>
      <description>Thank you Tom！
You enriched my imagination  about the string  "hello","world!"</description>
      <pubDate>Mon, 06 Nov 2023 02:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-confusion-about-macro-variable/m-p/901661#M356324</guid>
      <dc:creator>duanzongran</dc:creator>
      <dc:date>2023-11-06T02:17:03Z</dc:date>
    </item>
  </channel>
</rss>

