<?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: Run macro on a list of values or a dataset containing table names in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-macro-on-a-list-of-values-or-a-dataset-containing-table/m-p/484430#M31399</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Re: First why are you storing multiple dataset names in one observation instead of in many observations?&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I tried storing it in a single column and use it. But failed at running the macro step. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; _null_&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; tbl_names&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  call &lt;SPAN class="token keyword"&gt;execute&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'%nrstr(%st)('&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;table_name&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;');'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Call execute worked. I was not aware of this. I am going to research more on this and nrstr.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you for your quick response.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Aug 2018 16:07:00 GMT</pubDate>
    <dc:creator>r0oki3</dc:creator>
    <dc:date>2018-08-06T16:07:00Z</dc:date>
    <item>
      <title>Run macro on a list of values or a dataset containing table names</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-macro-on-a-list-of-values-or-a-dataset-containing-table/m-p/484408#M31396</link>
      <description>&lt;P&gt;This is something I am working on:&lt;/P&gt;&lt;P&gt;1. I have a main dataset (A) on which I am applying filters to see the data that I have to edit manually.&lt;/P&gt;&lt;P&gt;2. Once the filtered datasets are created and I have edited the data manually in SAS EG, I want to update the main dataset (A) with the values from the filtered datasets. For this I am sorting the filtered datasets and then using data step and update t1 t2.&lt;/P&gt;&lt;P&gt;3. I have written a macro with proc sort in it and I can call it 10 times for 10 datasets and run the data step and update ten times to update the values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe we can call a macro on an array. These are the steps I tried&lt;/P&gt;&lt;P&gt;1. I created a dataset tbl_names containing the table names, tried to create an array tbl_list and then call the macro in a do loop but it did not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro st(ds);&lt;BR /&gt;proc sort data = &amp;amp;ds;&lt;BR /&gt;by address_line_1;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data tbl_names;&lt;BR /&gt;input tbl_names1- &lt;SPAN&gt;tbl_names10 (:&amp;nbsp;&lt;/SPAN&gt;$35);&lt;BR /&gt;datalines;&lt;/P&gt;&lt;P&gt;t1 t2 t3;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used an example to define the above dataset&amp;nbsp;&lt;SPAN&gt;tbl_names&lt;/SPAN&gt; but this statement (&lt;SPAN&gt;input tbl_names1-&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;tbl_names10 (:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;$35);&lt;/SPAN&gt;) is currently not working.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set tbl_names;&lt;BR /&gt;array tbl_list[*] &lt;SPAN&gt;tbl_names1-&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;tbl_names10&lt;/SPAN&gt;;&lt;BR /&gt;do i=1 to dim(tbl_list);&lt;BR /&gt;%st(tbl_list(i));&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Parts of this code may not be working, I tried to re write but I was not able to. The code is just to give a picture of what I am trying to achieve.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 15:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-macro-on-a-list-of-values-or-a-dataset-containing-table/m-p/484408#M31396</guid>
      <dc:creator>r0oki3</dc:creator>
      <dc:date>2018-08-06T15:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro on a list of values or a dataset containing table names</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-macro-on-a-list-of-values-or-a-dataset-containing-table/m-p/484427#M31397</link>
      <description>&lt;P&gt;The first error in your code is that you added a semi-colon to the end of your line of data.&amp;nbsp; SAS will treat any dataline with semi-colon on it as marking the end of the input and any other characters on that line are ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other errors or more about the logic of what you are trying to do.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First why are you storing multiple dataset names in one observation instead of in many observations?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tbl_names;
  length table_name $41 ;
  input table_name @@ ;
datalines;
t1 t2 
t3
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that 41 characters should be enough for an 8 character libref plus a period plus a 32 character member name.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second you cannot run a PROC SORT step in the middle of a DATA STEP.&amp;nbsp; So if you want to use a data step to generate code it will be code that runs AFTER the data step finishes.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to do that is to use CALL EXECUTE().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set tbl_names;
  call execute(cats('%st(',table_name,');'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if your macro is complicated and uses macro variables it generates to control the logic of the macro then you will have a timing issue as CALL EXECUTE() will push the SAS statements the macro generates onto the stack to run.&lt;/P&gt;
&lt;P&gt;If you add %NRSTR() then the macro call itself will be pushed onto the stack and timing issues will be avoided.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set tbl_names;
  call execute(cats('%nrstr(%st)(',table_name,');'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 15:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-macro-on-a-list-of-values-or-a-dataset-containing-table/m-p/484427#M31397</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-06T15:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro on a list of values or a dataset containing table names</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-macro-on-a-list-of-values-or-a-dataset-containing-table/m-p/484430#M31399</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Re: First why are you storing multiple dataset names in one observation instead of in many observations?&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I tried storing it in a single column and use it. But failed at running the macro step. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; _null_&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; tbl_names&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  call &lt;SPAN class="token keyword"&gt;execute&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'%nrstr(%st)('&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;table_name&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;');'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Call execute worked. I was not aware of this. I am going to research more on this and nrstr.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you for your quick response.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 16:07:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-macro-on-a-list-of-values-or-a-dataset-containing-table/m-p/484430#M31399</guid>
      <dc:creator>r0oki3</dc:creator>
      <dc:date>2018-08-06T16:07:00Z</dc:date>
    </item>
  </channel>
</rss>

