<?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: Temporary tables inside a macro not overwrite tables of same name outside of macro? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715884#M221160</link>
    <description>&lt;P&gt;While the advice you have gotten so far is all true, you can work around this with minimal change to your macros.&amp;nbsp; Define a folder using the LIBNAME statement, such as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname my_temp 'path to some folder';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then modify the macros slightly, adding a line at the beginning and a line at the end:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymac1;
   options user=my_temp;
   
   all of the macro language logic goes here, unchanged.

   options user=work;
%mend mymac1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When running the macro, all single-level data set names will be written to the MY_TEMP folder.&amp;nbsp; Once the macro completes, SAS reverts to saving single level data set names in the WORK library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When done, MY_TEMP does not get cleaned out.&amp;nbsp; You would have to tend to that yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, if your macro reads from (rather than writes to) single-level names, it will attempt to read from MY_TEMP.&amp;nbsp; If you want to read from a file in the WORK library, you would have to refer to it as work.data-set-name.&lt;/P&gt;</description>
    <pubDate>Mon, 01 Feb 2021 20:54:48 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2021-02-01T20:54:48Z</dc:date>
    <item>
      <title>Temporary tables inside a macro not overwrite tables of same name outside of macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715875#M221154</link>
      <description>&lt;P&gt;Is there a way to have tables created inside a macro be independent of tables outside of the macro?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So that tables outside of the macro that have the same name will not be overwritten?&lt;/P&gt;
&lt;P&gt;Similar to how you can identify a macrovariable as %LOCAL.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 19:21:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715875#M221154</guid>
      <dc:creator>mcook</dc:creator>
      <dc:date>2021-02-01T19:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: Temporary tables inside a macro not overwrite tables of same name outside of macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715878#M221156</link>
      <description>&lt;P&gt;Tables of the same name must be written to a different SAS library or the new table will overwrite the existing table. The tables written by SAS code generated from a macro are in no way associated with the macro itself.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 19:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715878#M221156</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2021-02-01T19:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Temporary tables inside a macro not overwrite tables of same name outside of macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715881#M221158</link>
      <description>Unfortunately not. What I do, is use _ in front of my table names and temp tables within my macros. Then I drop all temp tables at the end of each macro execution explicitly (proc datasets) to avoid any issues with tables existing in a new run and save the output to a unique name or append it to a data set as required.</description>
      <pubDate>Mon, 01 Feb 2021 20:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715881#M221158</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-01T20:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Temporary tables inside a macro not overwrite tables of same name outside of macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715884#M221160</link>
      <description>&lt;P&gt;While the advice you have gotten so far is all true, you can work around this with minimal change to your macros.&amp;nbsp; Define a folder using the LIBNAME statement, such as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname my_temp 'path to some folder';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then modify the macros slightly, adding a line at the beginning and a line at the end:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymac1;
   options user=my_temp;
   
   all of the macro language logic goes here, unchanged.

   options user=work;
%mend mymac1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When running the macro, all single-level data set names will be written to the MY_TEMP folder.&amp;nbsp; Once the macro completes, SAS reverts to saving single level data set names in the WORK library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When done, MY_TEMP does not get cleaned out.&amp;nbsp; You would have to tend to that yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, if your macro reads from (rather than writes to) single-level names, it will attempt to read from MY_TEMP.&amp;nbsp; If you want to read from a file in the WORK library, you would have to refer to it as work.data-set-name.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 20:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715884#M221160</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-02-01T20:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Temporary tables inside a macro not overwrite tables of same name outside of macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715891#M221162</link>
      <description>&lt;P&gt;You can assign a macro variable name value like &lt;STRONG&gt;WORK.TMP&amp;lt;timestamp&amp;gt;&amp;nbsp;&lt;/STRONG&gt;to be used as temporary dataset name, with significant probability that is unique, and use it across the macro program.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 21:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715891#M221162</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-01T21:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Temporary tables inside a macro not overwrite tables of same name outside of macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715907#M221167</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;When done, MY_TEMP does not get cleaned out.&amp;nbsp; You would have to tend to that yourself.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/319809"&gt;@mcook&lt;/a&gt;: If you want to have SAS do the clean-up automatically (when closing the session), use a subfolder of the WORK library as the location of library MY_TEMP. See, e.g., &lt;A href="https://communities.sas.com/t5/SAS-Programming/establishing-additional-quot-work-quot-libraries/m-p/477975/highlight/true#M123191" target="_blank" rel="noopener"&gt;this 2018 post by Chris Hemedinger himself&lt;/A&gt; for an elegant way to do this (including uniqueness of the subfolder names and automatic subfolder creation thanks to system option DLCREATEDIR).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: An additional advantage of using a subfolder of the WORK library is that no name conflicts can occur even if two SAS sessions using your macro run in parallel on the same computer.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 23:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715907#M221167</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-01T23:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Temporary tables inside a macro not overwrite tables of same name outside of macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715912#M221170</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;While the advice you have gotten so far is all true, you can work around this with minimal change to your macros.&amp;nbsp; Define a folder using the LIBNAME statement, such as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname my_temp 'path to some folder';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then modify the macros slightly, adding a line at the beginning and a line at the end:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymac1;
   options user=my_temp;
   
   all of the macro language logic goes here, unchanged.

   options user=work;
%mend mymac1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When running the macro, all single-level data set names will be written to the MY_TEMP folder.&amp;nbsp; Once the macro completes, SAS reverts to saving single level data set names in the WORK library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When done, MY_TEMP does not get cleaned out.&amp;nbsp; You would have to tend to that yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, if your macro reads from (rather than writes to) single-level names, it will attempt to read from MY_TEMP.&amp;nbsp; If you want to read from a file in the WORK library, you would have to refer to it as work.data-set-name.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a great tip, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt; . But how would you handle it if the macro has internal data sets, but the macro is also &lt;EM&gt;supposed&lt;/EM&gt; to create output data sets in the WORK library?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 23:31:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/715912#M221170</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-01T23:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: Temporary tables inside a macro not overwrite tables of same name outside of macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/716063#M221244</link>
      <description>&lt;P&gt;If most of the one-level data set names should be discarded, but a few need to be saved in the WORK library, you can hard-code the two-part name:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.dsn5;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Feb 2021 13:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-inside-a-macro-not-overwrite-tables-of-same/m-p/716063#M221244</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-02-02T13:33:41Z</dc:date>
    </item>
  </channel>
</rss>

