<?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: Reference to a variable dataset name within a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682028#M206417</link>
    <description>&lt;P&gt;Since you always create the same dataset in the macro, only the result of the last macro call will "survive".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS "does not work" on its own without further details is a very stupid and unhelpful statement.&lt;/P&gt;</description>
    <pubDate>Mon, 07 Sep 2020 14:58:06 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-09-07T14:58:06Z</dc:date>
    <item>
      <title>Reference to a variable dataset name within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682014#M206405</link>
      <description>&lt;P&gt;i have a dataset "distincttenants" with following values: xxx yyy zzz I would like to be able to refer correctly in the macro "do" to the datasets prodxxx, prodyyy, prodzzz. How do I need to write the code to reference to the correct dataset ? obviously the text "prod" together (&amp;amp;) with the macro variable which i tried in the example below does not work. thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro do(tenant=); &lt;BR /&gt;proc sql; &lt;BR /&gt;create table a1 as select * from prod&amp;amp;tenant.; &lt;BR /&gt;quit; &lt;BR /&gt;%mend do; &lt;BR /&gt;&lt;BR /&gt;data distincttenants; &lt;BR /&gt;set distincttenants; &lt;BR /&gt;str=catt('%do(tenant=',tenantid,');'); &lt;BR /&gt;call execute(str); &lt;BR /&gt;run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Sep 2020 13:31:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682014#M206405</guid>
      <dc:creator>VCucu</dc:creator>
      <dc:date>2020-09-07T13:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: Reference to a variable dataset name within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682017#M206408</link>
      <description>&lt;P&gt;There are two things you need to do to get started.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, change the name of the macro.&amp;nbsp; %DO is a macro key word, and so would be illegal as the name of a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, write a call to the macro that works for a single data set instead of trying to do all three data sets at once.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have those pieces in place, you can re-post and get some help in how to call the macro three times.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 13:44:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682017#M206408</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-09-07T13:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: Reference to a variable dataset name within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682019#M206410</link>
      <description>&lt;P&gt;1) thats fine, it was for illustration purpose; i have another one which is not "do" in the real application&lt;/P&gt;
&lt;P&gt;2) i basically want to refer in a macro to a dataset name&amp;nbsp; which is composed of two parts&lt;/P&gt;
&lt;P&gt;- fixed text "prod"&lt;/P&gt;
&lt;P&gt;- variable text coming from macro variable "xxx", "yyy", "zzz"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in the example provided using "prod&amp;amp;tenant." does not work&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 13:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682019#M206410</guid>
      <dc:creator>VCucu</dc:creator>
      <dc:date>2020-09-07T13:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: Reference to a variable dataset name within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682021#M206412</link>
      <description>&lt;P&gt;so i have prodxxx, prodyyy and prodzzz tables however SAS compiler within the macro does not understand i want to select from these datasets if i use "prod&amp;amp;tenant.";&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 13:52:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682021#M206412</guid>
      <dc:creator>VCucu</dc:creator>
      <dc:date>2020-09-07T13:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: Reference to a variable dataset name within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682022#M206413</link>
      <description>&lt;P&gt;There are many places where the logic could break down.&amp;nbsp; That's why I asked for a simple macro call that processes one value.&amp;nbsp; For example, what happens when you try to run:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macroname_instead_of_do (tenant=xxx)&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 13:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682022#M206413</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-09-07T13:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Reference to a variable dataset name within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682024#M206415</link>
      <description>&lt;P&gt;I am going to second the request from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;That's why I asked for a simple macro call that processes one value.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;We have to see your code, and as requested, we need to see code that works on one value. Words will not get us there.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 14:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682024#M206415</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-07T14:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: Reference to a variable dataset name within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682028#M206417</link>
      <description>&lt;P&gt;Since you always create the same dataset in the macro, only the result of the last macro call will "survive".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS "does not work" on its own without further details is a very stupid and unhelpful statement.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 14:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682028#M206417</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-07T14:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: Reference to a variable dataset name within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682039#M206421</link>
      <description>&lt;P&gt;What part of it does not work?&amp;nbsp; The posted code looks fine.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To test the code try it without any macro logic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let tenant=xxx;
proc contents data=prod&amp;amp;tenant ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sometimes in macros the parser can get confused about what you want to treat as a single token.&amp;nbsp; You can fix this with %unquote()&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=%unquote(prod&amp;amp;tenant) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or simply assigning the generated name to a new macro variable and use that so there is no confusion about whether it is one token or two.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsname=prod&amp;amp;tenant;
proc contents data=&amp;amp;dsname ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Sep 2020 16:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682039#M206421</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-07T16:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Reference to a variable dataset name within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682060#M206433</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for the feedback. Your suggestion solved my issue.&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;%unquote(prod&amp;amp;tenant) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Best regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 19:02:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-to-a-variable-dataset-name-within-a-macro/m-p/682060#M206433</guid>
      <dc:creator>VCucu</dc:creator>
      <dc:date>2020-09-07T19:02:38Z</dc:date>
    </item>
  </channel>
</rss>

