To any of the developers that have worked on SASUnit,
I am fascinated by the way SASUnit appears to get object-orientated behaviour from macros but am having trouble understanding how the mechanism works.
As an example, the macro "%_sasunit_getPgmDesc" defined in "_sasunit_getpgmdesc.sas" appears to return the description string to its parent function in a local macro variable named "r_desc".
The following code found in "runsasunit.sas" uses the macro:
/-- save description and start date and time of scenario --------------/
%_sasunit_getPgmDesc (i_pgmfile=&&l_scnfile&i, r_desc=l_scndesc)
The remainder of the code in the script seems to imply that the code above populates the macro variable "l_scndesc" with the latest description.
a) Is my observation correct? Have you managed to return local macro variables from a macro?
b) If so, please could you explain how the mechanism works?
Regards,
Ross
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2014-01-07
Hi Ross,
it is possible with SAS to pass from macros back to the caller, as we did it here.
The fact is that you create a local variable in your calling macro (here: l_scndesc). Now you pass the Name of the macro variable to the called macro.
In the called macro you can then bind the value to te resolved macro variabel name like this:
%LET &r_desc. = <New Value>;
Strictly speaking this is no object orientation. It is simply call be reference.
Regards
Klaus
Last edit: Andreas Mangold 2014-01-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is a simple example. It is important that the macro variable being assigned exists in the scope of the calling program. So you have to define it there by assigning it a value (as I do in the example) or with a %local or %global statement. It does not need to be global, as even local variables will also be visible in nested macro calls.
To any of the developers that have worked on SASUnit,
I am fascinated by the way SASUnit appears to get object-orientated behaviour from macros but am having trouble understanding how the mechanism works.
As an example, the macro "%_sasunit_getPgmDesc" defined in "_sasunit_getpgmdesc.sas" appears to return the description string to its parent function in a local macro variable named "r_desc".
The following code found in "runsasunit.sas" uses the macro:
/-- save description and start date and time of scenario --------------/
%_sasunit_getPgmDesc (i_pgmfile=&&l_scnfile&i, r_desc=l_scndesc)
The remainder of the code in the script seems to imply that the code above populates the macro variable "l_scndesc" with the latest description.
a) Is my observation correct? Have you managed to return local macro variables from a macro?
b) If so, please could you explain how the mechanism works?
Regards,
Ross
Hi Ross,
it is possible with SAS to pass from macros back to the caller, as we did it here.
The fact is that you create a local variable in your calling macro (here: l_scndesc). Now you pass the Name of the macro variable to the called macro.
In the called macro you can then bind the value to te resolved macro variabel name like this:
%LET &r_desc. = <New Value>;
Strictly speaking this is no object orientation. It is simply call be reference.
Regards
Klaus
Last edit: Andreas Mangold 2014-01-07
Here is a simple example. It is important that the macro variable being assigned exists in the scope of the calling program. So you have to define it there by assigning it a value (as I do in the example) or with a %local or %global statement. It does not need to be global, as even local variables will also be visible in nested macro calls.