<?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 %str() in passing variable trouble in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/400660#M278666</link>
    <description>&lt;P&gt;The macro quoting is confusing the SAS parser and it is seeing the concatenated dataset name as multiple tokens.&lt;/P&gt;
&lt;P&gt;You could remove the macro quoting using %unquote().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(prim =, doselv =);
data %unquote(Prim_&amp;amp;prim._) (Keep = VARIABLE &amp;amp;DOSELV);;
set %unquote(mock.&amp;amp;PRIM);
run;
%mend;
%test(prim =%str(T_AE21110P3), doselv =C1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Frequently I find you can also solve this by just using a local macro variable to hold the generated name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(prim =, doselv =);
%local target source;
%let target=%unquote(Prim_&amp;amp;prim._);
%let source=%unquote(mock.&amp;amp;PRIM.);
data  &amp;amp;target (Keep = VARIABLE &amp;amp;DOSELV);;
set &amp;amp;source;
run;
%mend;
%test(prim =%str(T_AE21110P3), doselv =C1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 09 Oct 2017 14:58:22 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-10-09T14:58:22Z</dc:date>
    <item>
      <title>macro %str() in passing variable trouble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/400641#M278665</link>
      <description>&lt;P&gt;I had following code but dataset name won't take passed macro parameters with %str():&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; test(prim =, doselv =);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;data Prim_&amp;amp;prim._ (Keep = VARIABLE &amp;amp;DOSELV);;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;set &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New"&gt;mock.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New"&gt;PRIM.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;%&lt;STRONG&gt;&lt;I&gt;test&lt;/I&gt;&lt;/STRONG&gt;(prim =&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;%str&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;(T_AE21110P3), doselv =C1);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;Problem: prim_T_AE21110p3_ was not created as expected. only prim_ was in WORK folder.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;log:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;NOTE: There were 2 observations read from the data set MOCK.T_AE21110P3.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.PRIM_ has 2 observations and 22 variables.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.T_AE21110P3_ has 2 observations and 2 variables.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.00 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 16:26:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/400641#M278665</guid>
      <dc:creator>donghuazeng</dc:creator>
      <dc:date>2017-10-03T16:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: macro %str() in passing variable trouble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/400660#M278666</link>
      <description>&lt;P&gt;The macro quoting is confusing the SAS parser and it is seeing the concatenated dataset name as multiple tokens.&lt;/P&gt;
&lt;P&gt;You could remove the macro quoting using %unquote().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(prim =, doselv =);
data %unquote(Prim_&amp;amp;prim._) (Keep = VARIABLE &amp;amp;DOSELV);;
set %unquote(mock.&amp;amp;PRIM);
run;
%mend;
%test(prim =%str(T_AE21110P3), doselv =C1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Frequently I find you can also solve this by just using a local macro variable to hold the generated name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(prim =, doselv =);
%local target source;
%let target=%unquote(Prim_&amp;amp;prim._);
%let source=%unquote(mock.&amp;amp;PRIM.);
data  &amp;amp;target (Keep = VARIABLE &amp;amp;DOSELV);;
set &amp;amp;source;
run;
%mend;
%test(prim =%str(T_AE21110P3), doselv =C1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Oct 2017 14:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/400660#M278666</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-09T14:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: macro %str() in passing variable trouble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/400741#M278667</link>
      <description>&lt;P&gt;The example you use has no need for the %str to pass a value.&lt;/P&gt;
&lt;P&gt;Do you have a more complex version that you can share that might actually require the use of %str ? If not then use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;%&lt;STRONG&gt;&lt;I&gt;test&lt;/I&gt;&lt;/STRONG&gt;(prim = &lt;/FONT&gt;&lt;FONT face="Courier New"&gt;T_AE21110P3, doselv =C1);&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 19:12:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/400741#M278667</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-03T19:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: macro %str() in passing variable trouble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/402367#M278668</link>
      <description>&lt;P&gt;Thanks, Tom!&lt;/P&gt;&lt;P&gt;it is very helpful.&amp;nbsp; I realized that %str() here is not necessary.&amp;nbsp;Is it particularly sensitive when SAS takes it as a dataset name?&amp;nbsp;I mean if I pass a macro variable&amp;nbsp; with&amp;nbsp;%str() for non-dataset name, do I still have this trouble?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in this case, %str() only acted negatively for newly created dataset: work.prim_&amp;amp;prim_,&amp;nbsp; but existing dataset Mock.&amp;amp;prim&lt;/P&gt;&lt;P&gt;&amp;nbsp;has not such a trouble.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Don&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 13:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/402367#M278668</guid>
      <dc:creator>donghuazeng</dc:creator>
      <dc:date>2017-10-09T13:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: macro %str() in passing variable trouble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/402372#M278669</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169231"&gt;@donghuazeng&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks, Tom!&lt;/P&gt;
&lt;P&gt;it is very helpful.&amp;nbsp; I realized that %str() here is not necessary.&amp;nbsp;Is it particularly sensitive when SAS takes it as a dataset name?&amp;nbsp;I mean if I pass a macro variable&amp;nbsp; with&amp;nbsp;%str() for non-dataset name, do I still have this trouble?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in this case, %str() only acted negatively for newly created dataset: work.prim_&amp;amp;prim_,&amp;nbsp; but existing dataset Mock.&amp;amp;prim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;has not such a trouble.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;Don&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I suspect that the difference is that in the first you are trying to build one word from a combination of text and a macro expression. But in the second the whole member name is coming from the macro variable. I suspect that SAS is already parsing the libref period and member name as three different tokens and so the macro quoting is not confusing.&lt;/P&gt;
&lt;PRE&gt;5    %let x=%str(ss);
6    %let y=%str(class);
7    proc print data=sashelp.cla&amp;amp;x ; run;
ERROR: File SASHELP.CLA.DATA does not exist.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.06 seconds
      cpu time            0.00 seconds

NOTE: Line generated by the macro variable "X".
7    sashelp.class
                --
                22
                 --
                 202

ERROR 22-322: Syntax error, expecting one of the following: ;, (, BLANKLINE, CONTENTS, DATA,
              DOUBLE, GRANDTOTAL_LABEL, GRANDTOT_LABEL, GRAND_LABEL, GTOTAL_LABEL, GTOT_LABEL,
              HEADING, LABEL, N, NOOBS, NOSUMLABEL, OBS, ROUND, ROWS, SPLIT, STYLE, SUMLABEL,
              UNIFORM, WIDTH.

ERROR 202-322: The option or parameter is not recognized and will be ignored.


8    proc print data=sashelp.&amp;amp;y ; run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Oct 2017 14:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/402372#M278669</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-09T14:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: macro %str() in passing variable trouble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/402396#M278670</link>
      <description>&lt;P&gt;HI, Tom:&lt;/P&gt;&lt;P&gt;I set the options of symbolgen mprint mlogic and passed the same %str(Prim)&lt;/P&gt;&lt;P&gt;1) it is strange that&amp;nbsp;the log&amp;nbsp;showed data.prim_&amp;amp;prim was correctly resolved. however, there are notes&amp;nbsp;of "unquoted ....";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; and later the WORK folder still has Prim_&amp;nbsp; (missed &amp;amp;prim)&lt;/P&gt;&lt;P&gt;2) if I did data step as: data.&amp;amp;prim_, it will resolve &amp;amp;prim. but with note of "unquoted...."&lt;/P&gt;&lt;P&gt;this may be the case when you said "concatenate":&amp;nbsp; any leading letter for &amp;amp;prim will cause missing of &amp;amp;prim if it is passed with %str().&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks you so much for clarification.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Don&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 15:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/402396#M278670</guid>
      <dc:creator>donghuazeng</dc:creator>
      <dc:date>2017-10-09T15:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: macro %str() in passing variable trouble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/402409#M278671</link>
      <description>&lt;P&gt;It does NOT physically add a space between the strings it just internally thinks that the string is multiple&amp;nbsp;words because of the presence of the macro quoting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is what is so confusing about this error since the generated string looks right but SAS is not interpreting it right.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 15:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/402409#M278671</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-09T15:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: macro %str() in passing variable trouble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/402433#M278672</link>
      <description>&lt;P&gt;excellent!&amp;nbsp;&amp;nbsp; very much appreicated&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 17:23:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-str-in-passing-variable-trouble/m-p/402433#M278672</guid>
      <dc:creator>donghuazeng</dc:creator>
      <dc:date>2017-10-09T17:23:54Z</dc:date>
    </item>
  </channel>
</rss>

