06-06-2013 07:19 AM
I am trying to get a macro to work that will send in a variable in order to read a database, and then return the variable it reads off the database.
The macro works correctly, as I can see from the proc print showing the db read worked. But how to I pluck the variable value it reads from working memory and return it to the calling program? These are 2 completely separate pieces of code - the macro is not within the main module of code, it is a separate file.
format passvar1 $3.;
Var_i_want_populated = the value that was read in the mymacro macro;
var_that_was_read_from_the_database DOES have a value in it and I want to return it to the calling module so that I can assign its value to Var_i_want_populated.
Does anyone know how to do this?
06-06-2013 07:35 AM
You will need to show us the macro definition and eventually an execution log in order to give you advice.
Just as a thought: You could have a timing problem here:
Call execute "Resolves the argument, and issues the resolved value for execution at the next step boundary."
It doesn't matter that your code is stored in separate .sas files. It still will be executed together within the same environment.
06-06-2013 07:39 AM
That was exactly what I was thinking as well. Have you tried assigning the value in a new data step. I am also assuming that your variable assignment code is actually something similar to:
var_I_want_populated = "&random_var_name" ;
06-06-2013 07:38 AM
If you could know the macro variable name which holds the value in the macro(a separate file). You can do in these 3 ways
1. Define the Macro variable as GLOBAL which holds the results and if done this value can be used in the calling program.
2. If you are aware of the name of macro variable then you can get the value by fetching the value from sashelp.vtable
3. This one is weird. Create a additional parameter in the Macro which holds the results and use it in the calling.
%local input result;
%put Result = &result;
Let me know if this answers your question.....
06-06-2013 07:45 AM
This might be a simple case of using the %global macro statement, but I'm not sure I fully understand the situation, e.g:
Does mymacro invoke some SQL?
Does mymacro create a table / dataset of results?
Can mymacro be changed to use "call symput('random_var_name',put(var_that_was_read_from_the_database)); " as part of a data step?
May be the above can be all answered if you share the code for mymacro.
06-09-2013 03:59 AM
Have a look at the DOSUBL function.
There is no way call execute can invoke code that returns a value to the data step with that call execute syntax.
Another way might be to create your own call routine or a user defined function with PROC FCMP. Both these and DOSUBL complete their process before the following line in the data step continues execution.