<?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: local SAS dataset within a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/local-SAS-dataset-within-a-macro/m-p/109137#M22684</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Short answer is no.&amp;nbsp; But there is more than one way to skin a cat.&lt;/P&gt;&lt;P&gt;Probably the easiest way is to pass the names of the datasets you want to use as parameters to your macro call rather than hardcoding dataset names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS uses libraries to store datasets. You could generate a new directory and point a new libref to it (sort of like building your own stack?).&amp;nbsp; You will need to have a way to generate a unique directory name.&amp;nbsp; Not sure if SAS has that, but if you are on unix there are tools for that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you do not specify a LIBREF when creating a dataset then it is in the WORK library.&amp;nbsp; If you use the WORK library then you could generate a unique dataset name using prefixes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that SAS will automatically name datasets with DATA1, DATA2, ... if you do not specify a dataset name in your DATA statement.&amp;nbsp; You can use that create your unique dataset names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Say you want to call to a macro needs three dataset names.&amp;nbsp; Make three empty datasets to generate some unique names and store the names into macro variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data ; run;&lt;/P&gt;&lt;P&gt;%let name1=&amp;amp;syslast;&lt;/P&gt;&lt;P&gt;data; run;&lt;/P&gt;&lt;P&gt;%let name2=&amp;amp;syslast;&lt;/P&gt;&lt;P&gt;data; run;&lt;/P&gt;&lt;P&gt;%let name3=&amp;amp;syslast;&lt;/P&gt;&lt;P&gt;%mymacro(ds1=&amp;amp;name1,ds2=&amp;amp;name2,ds3=&amp;amp;name3)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 Jul 2012 21:58:28 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2012-07-16T21:58:28Z</dc:date>
    <item>
      <title>local SAS dataset within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-SAS-dataset-within-a-macro/m-p/109136#M22683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all:&lt;/P&gt;&lt;P&gt; I am wondering whether there is a way to define local/global SAS dataset? I am writing a Macro within which several temporary datasets will be created and merged. I want those temporary datasets to be local within the Macro definition so that I wouldn't accidentally overwrite any existing global datasets with the same name. I know SAS distinguishes local/global Macro variable but I cannot find an analogy for datasets. Is there any way to do that in SAS, like local/global objects in other languages such as C++ or Java? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2012 21:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-SAS-dataset-within-a-macro/m-p/109136#M22683</guid>
      <dc:creator>tradepeter</dc:creator>
      <dc:date>2012-07-16T21:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: local SAS dataset within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-SAS-dataset-within-a-macro/m-p/109137#M22684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Short answer is no.&amp;nbsp; But there is more than one way to skin a cat.&lt;/P&gt;&lt;P&gt;Probably the easiest way is to pass the names of the datasets you want to use as parameters to your macro call rather than hardcoding dataset names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS uses libraries to store datasets. You could generate a new directory and point a new libref to it (sort of like building your own stack?).&amp;nbsp; You will need to have a way to generate a unique directory name.&amp;nbsp; Not sure if SAS has that, but if you are on unix there are tools for that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you do not specify a LIBREF when creating a dataset then it is in the WORK library.&amp;nbsp; If you use the WORK library then you could generate a unique dataset name using prefixes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that SAS will automatically name datasets with DATA1, DATA2, ... if you do not specify a dataset name in your DATA statement.&amp;nbsp; You can use that create your unique dataset names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Say you want to call to a macro needs three dataset names.&amp;nbsp; Make three empty datasets to generate some unique names and store the names into macro variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data ; run;&lt;/P&gt;&lt;P&gt;%let name1=&amp;amp;syslast;&lt;/P&gt;&lt;P&gt;data; run;&lt;/P&gt;&lt;P&gt;%let name2=&amp;amp;syslast;&lt;/P&gt;&lt;P&gt;data; run;&lt;/P&gt;&lt;P&gt;%let name3=&amp;amp;syslast;&lt;/P&gt;&lt;P&gt;%mymacro(ds1=&amp;amp;name1,ds2=&amp;amp;name2,ds3=&amp;amp;name3)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2012 21:58:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-SAS-dataset-within-a-macro/m-p/109137#M22684</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-07-16T21:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: local SAS dataset within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-SAS-dataset-within-a-macro/m-p/109138#M22685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you learning JAVA or C++ ?&lt;/P&gt;&lt;P&gt;As Tom said, you can't have local/global SAS dataset. SAS is not OOP language.&lt;/P&gt;&lt;P&gt;But as your required, Maybe dataset option gennum= is what you are looking for, which will generate lots of generation of original dataset, and keep the original dataset name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;GENNUM= Data Set Option&lt;/P&gt;&lt;P&gt;Specifies a particular generation of a SAS data set.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2012 04:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-SAS-dataset-within-a-macro/m-p/109138#M22685</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-07-17T04:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: local SAS dataset within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-SAS-dataset-within-a-macro/m-p/109139#M22686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all for the help. I guess I will need a way to uniquely name my temporary datasets. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2012 13:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-SAS-dataset-within-a-macro/m-p/109139#M22686</guid>
      <dc:creator>tradepeter</dc:creator>
      <dc:date>2012-07-17T13:38:37Z</dc:date>
    </item>
  </channel>
</rss>

