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).
Suggest you use this Google advanced search argument to find technical discussion on the topic as SAS support http://support.sas.com/ website.
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.
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.
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 &NAME1 and &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:
%let name1 = Mary;
%let name2 = William;
title "List for: &name1, &name2";
proc print data=sashelp.class;
where name in ("&name1", "&name2");
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:
title "List for selected students";
proc print data=sashelp.class;
where name in ("Mary", "William");
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 &NAME1 and &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.
Thanks Cynthia..that really helped me.
"It seems like you are confusing the storage of macro PROGRAMS with how to reference macro VARIABLES." - This line itself answered my question.
Here is what understood. running %freq will actually call my MACRO program which will create 2 macro variables &name1. &name2. .
Am I right??
Scott is correct in his recommendation. As I said in the rest of the paragraph:
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 &NAME1 and &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.
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.
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.