<?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: Storing and Resusing Macros in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21736#M4659</link>
    <description>Thanks Cynthia..that really helped me.&lt;BR /&gt;
"It seems like you are confusing the storage of macro PROGRAMS with how to reference macro VARIABLES." -  This line itself answered my question.&lt;BR /&gt;
Here is what understood. running %freq will actually call my MACRO program which will create 2 macro variables &amp;amp;name1. &amp;amp;name2. .&lt;BR /&gt;
Am I right??&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
    <pubDate>Tue, 24 Nov 2009 21:29:36 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-11-24T21:29:36Z</dc:date>
    <item>
      <title>Storing and Resusing Macros</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21733#M4656</link>
      <description>Hello,&lt;BR /&gt;
I would like to know on how to store and reuse macro variables.Thanks for your help in advance.&lt;BR /&gt;
&lt;BR /&gt;
I have created a dataset named mylib.demog.And I have created 2 macro variables name1, name2 and stored in an SAS macro library.&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;libname mylib 'C:\Documents and Settings\Desktop' ;&lt;BR /&gt;
data mylib.demog;&lt;BR /&gt;
input name $ marks;&lt;BR /&gt;
datalines;&lt;BR /&gt;
tom  20&lt;BR /&gt;
sam  40&lt;BR /&gt;
pete 45&lt;BR /&gt;
kat  55&lt;BR /&gt;
bat  32&lt;BR /&gt;
dell 67&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
options mstored sasmstore=mylib;&lt;BR /&gt;
%macro freq/store;&lt;BR /&gt;
  %let name1=%bquote('tom');&lt;BR /&gt;
  %let name2=%bquote('dell');&lt;BR /&gt;
 %put &amp;amp;name1.;&lt;BR /&gt;
 %put &amp;amp;name2.;&lt;BR /&gt;
%mend freq;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
Now when I run this below code, %freq prints 2 values - 'tom,'dell'  in the log file as expected.&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;options mstored sasmstore=mylib;&lt;BR /&gt;
%freq;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
Now if I want to use these 2 values , how do I use them ?&lt;BR /&gt;
For example , if want to print the data from mylib.demog datset where name in ('tom,'dell') using the macro %freq., How do i do that?&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Tue, 24 Nov 2009 18:09:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21733#M4656</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-11-24T18:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: Storing and Resusing Macros</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21734#M4657</link>
      <description>I expect you would want to declare the SAS macro variable names you are using as %GLOBAL variables - then you can use these macro variables in your code, but only after executing the OPTIONS statement as you identified and then by also invoking %FREQ; -- after the %GLOBAL references (or add the %GLOBAL to your FREQ macro code).&lt;BR /&gt;
&lt;BR /&gt;
Suggest you use this Google advanced search argument to find technical discussion on the topic as SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website.&lt;BR /&gt;
&lt;BR /&gt;
using macro store facility site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
SAS Macro Language: Reference, Scopes of Macro Variables&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002047080.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002047080.htm&lt;/A&gt;</description>
      <pubDate>Tue, 24 Nov 2009 18:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21734#M4657</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-11-24T18:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: Storing and Resusing Macros</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21735#M4658</link>
      <description>Hi:&lt;BR /&gt;
  There is a difference between storing the macro PROGRAM and referencing macro VARIABLES. The macro PROGRAM can be created and used within a session (where it would live in the WORK.SASMACR catalog) or it can be stored and referenced from an AUTOCALL library or it can be stored and referenced from a stored, compiled macro location. &lt;BR /&gt;
 &lt;BR /&gt;
  Macro VARIABLES, on the other hand, are somewhat ephemeral. They are not "stored" from session to session. They either live, within one session, in a GLOBAL symbol table or a LOCAL symbol table. However, if you store your macro PROGRAM, it is the creation method, the creation logic which you are storing -- NOT the macro VARIABLES themselves. Macro VARIABLES can be created in a variety of different ways, but they only "live" in memory for the duration of your session. One way to create macro variables is with %LET, another way is with CALL SYMPUT. Either of those methods work outside and inside a macro PROGRAM. So you have several different combinations of creation possibilities.&lt;BR /&gt;
 &lt;BR /&gt;
  It seems like you are confusing the storage of macro PROGRAMS with how to reference macro VARIABLES. Every time you run your %FREQ macro PROGRAM, it will, indeed, create 2 macro VARIABLES called &amp;amp;NAME1 and &amp;amp;NAME2 -- they will however, be LOCAL in scope -- that is, they will only live in the memory of the LOCAL symbol table for macro variables unless you explicitly make them GLOBAL. Consider this program:&lt;BR /&gt;
   &lt;BR /&gt;
[pre]&lt;BR /&gt;
%let name1 = Mary;&lt;BR /&gt;
%let name2 = William;&lt;BR /&gt;
               &lt;BR /&gt;
ods listing;&lt;BR /&gt;
title "List for: &amp;amp;name1, &amp;amp;name2";&lt;BR /&gt;
proc print data=sashelp.class;&lt;BR /&gt;
  where name in ("&amp;amp;name1", "&amp;amp;name2");&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                         &lt;BR /&gt;
You do not need a macro PROGRAM to create or use two macro variables. A good rule of thumb when designing a macro PROGRAM or process is to start with a WORKING program. In your case, you should start from the program that gives you the desired output. For example, to generate the above program, I started with this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
                           &lt;BR /&gt;
ods listing;&lt;BR /&gt;
title "List for selected students";&lt;BR /&gt;
proc print data=sashelp.class;&lt;BR /&gt;
  where name in ("Mary", "William");&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
            &lt;BR /&gt;
Then I figure out where I could use my macro VARIABLES, decided on the names of those macro VARIABLES and then tested them out in the program by assigning values to &amp;amp;NAME1 and &amp;amp;NAME2 and then using those macro VARIABLES to see whether they'd work in the program as it was written. As you can see, I decided to change the title to show the names that I was selecting.&lt;BR /&gt;
 &lt;BR /&gt;
Some information on the scope of macro VARIABLES can be found here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002293860.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002293860.htm&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001072159.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001072159.htm&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001072103.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001072103.htm&lt;/A&gt;               &lt;BR /&gt;
 &lt;BR /&gt;
A good introduction to the difference between macro VARIABLES and a macro PROGRAM is here:&lt;BR /&gt;
Doc on Using macro VARIABLES:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002047074.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002047074.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Intro to Macro Facility (user group paper):&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi28/056-28.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi28/056-28.pdf&lt;/A&gt;&lt;BR /&gt;
   &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 24 Nov 2009 18:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21735#M4658</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-11-24T18:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Storing and Resusing Macros</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21736#M4659</link>
      <description>Thanks Cynthia..that really helped me.&lt;BR /&gt;
"It seems like you are confusing the storage of macro PROGRAMS with how to reference macro VARIABLES." -  This line itself answered my question.&lt;BR /&gt;
Here is what understood. running %freq will actually call my MACRO program which will create 2 macro variables &amp;amp;name1. &amp;amp;name2. .&lt;BR /&gt;
Am I right??&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Tue, 24 Nov 2009 21:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21736#M4659</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-11-24T21:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Storing and Resusing Macros</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21737#M4660</link>
      <description>Yes, but you still have the issue with a GLOBAL versus a LOCAL macro, as previously mentioned.  You can see what macro variables are accessible using these commands:&lt;BR /&gt;
&lt;BR /&gt;
%PUT _LOCAL_;  &lt;BR /&gt;
&lt;BR /&gt;
%PUT _GLOBAL_;&lt;BR /&gt;
&lt;BR /&gt;
%PUT _AUTOMATIC_;&lt;BR /&gt;
&lt;BR /&gt;
..or..&lt;BR /&gt;
&lt;BR /&gt;
%PUT _ALL_;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 24 Nov 2009 21:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21737#M4660</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-11-24T21:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Storing and Resusing Macros</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21738#M4661</link>
      <description>Hi:&lt;BR /&gt;
  Scott is correct in his recommendation. As I said in the rest of the paragraph:&lt;BR /&gt;
&lt;B&gt;&lt;BR /&gt;
It seems like you are confusing the storage of macro PROGRAMS with how to reference macro VARIABLES. &lt;U&gt; Every time you run your %FREQ macro PROGRAM, it will, indeed, create 2 macro VARIABLES called &amp;amp;NAME1 and &amp;amp;NAME2 -- they will however, be LOCAL in scope -- that is, they will only live in the memory of the LOCAL symbol table for macro variables unless you explicitly make them GLOBAL. &lt;/U&gt;&lt;BR /&gt;
&lt;/B&gt;&lt;BR /&gt;
 &lt;BR /&gt;
  The documentation links that I posted have many good explanations of local versus global scope of macro variables. How to reference the macro variables created by your %FREQ program will be complicated even more if you do not understand the difference between LOCAL and GLOBAL macro variables.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 24 Nov 2009 23:30:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21738#M4661</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-11-24T23:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: Storing and Resusing Macros</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21739#M4662</link>
      <description>To tgt_sas  &lt;BR /&gt;
Yes, time for some reading, testing and learning with the SAS macro variable environment processing.  The questions are somewhat fundamental and can be revealed with individual experience and testing.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 25 Nov 2009 02:00:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Storing-and-Resusing-Macros/m-p/21739#M4662</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-11-25T02:00:31Z</dc:date>
    </item>
  </channel>
</rss>

