Macro Help: Storing and Reusing Macro Variables issue?

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

Macro Help: Storing and Reusing Macro Variables issue?

Dear all, The SAS processes that I have is run on sequence between intervals. So for example, once the first process is run, the SAS system terminates or in other words the session comes to a close. After a break or an interval, the second process begins to run and likewise several processes follow in this sequence.

In the above event, the macro variable values that are created as global macro variables in the first process needs to be used again in 3rd and 4th process and unfortunately it seems since the SAS system terminates between processes the macro variables values gets erased in the global symbol table i guess?

Please advice. Thanks


Accepted Solutions
Solution
‎08-19-2015 01:39 PM
Super User
Posts: 10,490

Re: Macro Help: Storing and Reusing Macro Variables issue?

It sounds like you need to write the values of the macro variables to a permanent data set that would be available to other programs or to a program file that would use %INCLUDE to make them available to the next session. The start of the following programs would have to read the dataset to assign values in the other session.

How many variables are there?

Do you know the names of the variables or are the names created during execution and you may not know all of them?

Depending on what you are doing specifically the data set might be useful in a using CALL Execute code.

Note that information about macros is kept in SASHELP.VMACRO or dictionary.macros. So it would be relatively simple to save the Global macro values. Anything local to a specific macro program would require additional work as above.

View solution in original post


All Replies
Occasional Contributor P_2
Occasional Contributor
Posts: 10

Re: Macro Help: Storing and Reusing Macro Variables issue?

You could store your macro variables in a permanent SAS dataset and then recall them before running a new process.

data perm.store;

     x = "&macro_var.";

run;

SAS Closes... Reopens

data _null_;

     set perm.store;

call symput("macro_var", x);

run;

Solution
‎08-19-2015 01:39 PM
Super User
Posts: 10,490

Re: Macro Help: Storing and Reusing Macro Variables issue?

It sounds like you need to write the values of the macro variables to a permanent data set that would be available to other programs or to a program file that would use %INCLUDE to make them available to the next session. The start of the following programs would have to read the dataset to assign values in the other session.

How many variables are there?

Do you know the names of the variables or are the names created during execution and you may not know all of them?

Depending on what you are doing specifically the data set might be useful in a using CALL Execute code.

Note that information about macros is kept in SASHELP.VMACRO or dictionary.macros. So it would be relatively simple to save the Global macro values. Anything local to a specific macro program would require additional work as above.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 207 views
  • 3 likes
  • 3 in conversation