<?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: Problem with macro variable resolution in dataset name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343140#M78748</link>
    <description>&lt;P&gt;Agree, in the code you have shown, quoting is not needed.&amp;nbsp; With the code shown, if you %unquote() it is works, i.e.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="4"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="4"&gt;%unquote&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt;(tbl1_3_&amp;amp;nmend);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this shouldn't be necessary (because it should be done automatically), but it fits with the general rule of "if you're using the macro language, and the generated SAS code looks correct, but it's not working correctly, try %unquote()".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note there are other situations where %unquote() can be used to "glue" together a token, see e.g. &lt;A href="http://www.sascommunity.org/wiki/Resolving_a_macro_variable_within_single_quotes" target="_blank"&gt;http://www.sascommunity.org/wiki/Resolving_a_macro_variable_within_single_quotes&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2017 01:30:18 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2017-03-22T01:30:18Z</dc:date>
    <item>
      <title>Problem with macro variable resolution in dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343090#M78724</link>
      <description>&lt;P&gt;I am having a problem I believe involves the resolution of a macro variable in a dataset name. It appears a space is being inserted between the first part of the name and the macro variable reference value, so that, instead of 1 name, I end up with 2 names. Below is sample code, and the log. The code was submitted immediately after SAS invocation (v9.4). The purpose of the %put and put statements is to show what the macro variable is resolving to.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro datatype(type);
  %global nmend;
  %if &amp;amp;type=enrolled %then %do;
    %let nmend=%str(enrl);
  %end;
  %else %do;
    %let nmend=%str(elig);
  %end;
%mend datatype;

%macro table1_3;
%put ***&amp;amp;nmend.***;
%put ***tbl1_3_&amp;amp;nmend.***;
%put ***%str(tbl1_3_&amp;amp;nmend.)***;
  data tbl1_3_&amp;amp;nmend.;
    name='Dave';
    age=22;
put "&amp;amp;nmend.";
put "tbl1_3_&amp;amp;nmend.";
put "%str(tbl1_3_&amp;amp;nmend.)";
    output;
  run;
%mend table1_3;

%datatype(elig)
%put &amp;amp;=nmend;
%table1_3&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;MLOGIC(DATATYPE):  Beginning execution.
MLOGIC(DATATYPE):  Parameter TYPE has value elig
MLOGIC(DATATYPE):  %GLOBAL  NMEND
SYMBOLGEN:  Macro variable TYPE resolves to elig
MLOGIC(DATATYPE):  %IF condition &amp;amp;type=enrolled is FALSE
MLOGIC(DATATYPE):  %LET (variable name is NMEND)
MLOGIC(DATATYPE):  Ending execution.
54   %put &amp;amp;=nmend;
SYMBOLGEN:  Macro variable NMEND resolves to elig
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
NMEND=elig
55   %table1_3
MLOGIC(TABLE1_3):  Beginning execution.
MLOGIC(TABLE1_3):  %PUT ***&amp;amp;nmend.***
SYMBOLGEN:  Macro variable NMEND resolves to elig
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
***elig***
MLOGIC(TABLE1_3):  %PUT ***tbl1_3_&amp;amp;nmend.***
SYMBOLGEN:  Macro variable NMEND resolves to elig
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
***tbl1_3_elig***
MLOGIC(TABLE1_3):  %PUT ***&amp;#1;tbl1_3_&amp;amp;nmend.&amp;#2;***
SYMBOLGEN:  Macro variable NMEND resolves to elig
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
***tbl1_3_elig***
SYMBOLGEN:  Macro variable NMEND resolves to elig
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
MPRINT(TABLE1_3):   data tbl1_3_elig;
MPRINT(TABLE1_3):   name='Dave';
MPRINT(TABLE1_3):   age=22;
SYMBOLGEN:  Macro variable NMEND resolves to elig
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
MPRINT(TABLE1_3):   put "elig";
SYMBOLGEN:  Macro variable NMEND resolves to elig
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
MPRINT(TABLE1_3):   put "tbl1_3_elig";
SYMBOLGEN:  Macro variable NMEND resolves to elig
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
MPRINT(TABLE1_3):   put "tbl1_3_elig";
MPRINT(TABLE1_3):   output;
MPRINT(TABLE1_3):   run;

elig
tbl1_3_elig
tbl1_3_elig
NOTE: The data set WORK.TBL1_3_ has 1 observations and 2 variables.
NOTE: The data set WORK.ELIG has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.03 seconds


MLOGIC(TABLE1_3):  Ending execution.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It appears the dataset has one name, tbl1_3_elig, but I end up with 2 datasets, tbl1_3_ and elig! I have done things like this zillions of times in the past and never encountered this. Any suggestions as to what's going on? Did I inadvertently set some kind of environmental variable that's causing this?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 22:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343090#M78724</guid>
      <dc:creator>jman</dc:creator>
      <dc:date>2017-03-21T22:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with macro variable resolution in dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343095#M78727</link>
      <description>&lt;P&gt;I removed all the %STR() and didn't have any issues, with %STR() I had the same issues you did.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 22:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343095#M78727</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-21T22:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with macro variable resolution in dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343098#M78730</link>
      <description>&lt;P&gt;What happens when you change&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; nmend&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token macrostatement"&gt;%str&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;elig&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;to&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; nmend&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;elig;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;and similar for ENRL?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;What makes you think that you need %str(elig)? There are no special characters involved that I can see that would require macro quoting (the %str function).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 22:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343098#M78730</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-21T22:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with macro variable resolution in dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343125#M78742</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SAS cannot unquote two levels of quotes

data %str(cla%str(ss));
  set sashelp.class;
run;quit;

%unquote(tbl1_3_&amp;amp;nmend.);

I don't know what you are trying to do. :)
But DOSUBL really heps with meta data.

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLA has 19 observations and 5 variables.
NOTE: The data set WORK.SS has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds

This works. I unquoted

%symdel nmend
    elig
    tbl1_3_elig;

%macro datatype(type);
  %global nmend;
  %if &amp;amp;type=enrolled %then %do;
    %let nmend=%str(enrl);
  %end;
  %else %do;
    %let nmend=%str(elig);
  %end;
%mend datatype;

%macro table1_3;
%put ***&amp;amp;nmend.***;
%put ***tbl1_3_&amp;amp;nmend.***;
%put ***%str(tbl1_3_&amp;amp;nmend.)***;
  data %unquote(tbl1_3_&amp;amp;nmend.);
    name='Dave';
    age=22;
put "&amp;amp;nmend.";
put "tbl1_3_&amp;amp;nmend.";
put "%str(tbl1_3_&amp;amp;nmend.)";
    output;
  run;
%mend table1_3;



&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, 22 Mar 2017 00:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343125#M78742</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-22T00:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with macro variable resolution in dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343126#M78743</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SAS cannot unquote two levels of quotes

data %str(cla%str(ss));
  set sashelp.class;
run;quit;

%unquote(tbl1_3_&amp;amp;nmend.);

I don't know what you are trying to do. :)
But DOSUBL really heps with meta data.

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLA has 19 observations and 5 variables.
NOTE: The data set WORK.SS has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds

This works. I unquoted

%symdel nmend
    elig
    tbl1_3_elig;

%macro datatype(type);
  %global nmend;
  %if &amp;amp;type=enrolled %then %do;
    %let nmend=%str(enrl);
  %end;
  %else %do;
    %let nmend=%str(elig);
  %end;
%mend datatype;

%macro table1_3;
%put ***&amp;amp;nmend.***;
%put ***tbl1_3_&amp;amp;nmend.***;
%put ***%str(tbl1_3_&amp;amp;nmend.)***;
  data %unquote(tbl1_3_&amp;amp;nmend.);
    name='Dave';
    age=22;
put "&amp;amp;nmend.";
put "tbl1_3_&amp;amp;nmend.";
put "%str(tbl1_3_&amp;amp;nmend.)";
    output;
  run;
%mend table1_3;



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 00:53:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343126#M78743</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-22T00:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with macro variable resolution in dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343140#M78748</link>
      <description>&lt;P&gt;Agree, in the code you have shown, quoting is not needed.&amp;nbsp; With the code shown, if you %unquote() it is works, i.e.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="4"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="4"&gt;%unquote&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt;(tbl1_3_&amp;amp;nmend);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this shouldn't be necessary (because it should be done automatically), but it fits with the general rule of "if you're using the macro language, and the generated SAS code looks correct, but it's not working correctly, try %unquote()".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note there are other situations where %unquote() can be used to "glue" together a token, see e.g. &lt;A href="http://www.sascommunity.org/wiki/Resolving_a_macro_variable_within_single_quotes" target="_blank"&gt;http://www.sascommunity.org/wiki/Resolving_a_macro_variable_within_single_quotes&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 01:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343140#M78748</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-03-22T01:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with macro variable resolution in dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343273#M78801</link>
      <description>&lt;P&gt;To all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much. I don't recall exactly what I did to arrive at this situation, but&amp;nbsp;I tried many things (not, however, unquoting. That's a good rule of thumb to know) to get rid of the apparent space that was being inserted in the dataset name. My paranoia drove me to put %str()s around everything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a test, I tried the following: %let nmend = %str(EQ)elig; Then data tbl1_3&amp;amp;nmend. gave me 2 datasets (tbl1_3 and EQelig), whereas data %unquote(tbl1_3&amp;amp;nmend) gave me one dataset (tbl1_3EQelig).&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 13:54:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-macro-variable-resolution-in-dataset-name/m-p/343273#M78801</guid>
      <dc:creator>jman</dc:creator>
      <dc:date>2017-03-22T13:54:13Z</dc:date>
    </item>
  </channel>
</rss>

