Hello,
Can we use Retain Keyword in Macro ? I believe not, Just wanted to confirm, if not what would be it's alternative for Macro to do incremental addition
Regards,
Jaiganesh
@jaiganesh wrote:
Retain Keyword (...) what would be it's alternative for Macro to do incremental addition
Hello @jaiganesh,
The primary purpose of the RETAIN statement in the DATA step is to prevent certain variables from being reset to missing at the beginning of a new iteration of the DATA step (implied loop).
In a SAS macro:
Example:
%macro test;
%let s=0;
%do i=20 %to 40 %by 10;
%let s=%eval(&s+&i);
%end;
%put &=s; /* result: 90 */
%mend test;
%test
May I ask where, when and why would the subject of Retain appear in a text processing facility that doesn't process PDV or in other words execution that's done by the datastep compiler. If you answer the 3 W's , that will help.
You do not, I repeat NOT, process data with the macro preprocessor, which is there only for making code dynamic, if such is needed.
Your question therefore shows a complete cluelessness about the subject. You need to deepen your understanding of the Base SAS language quite a lot before you even think about macros.
You can use a macro program to generate any SAS code (or any other text for that matter) so I don't see any reason why would have any trouble generating a RETAIN statement. Or for that matter use the word RETAIN as a the name of a variable or macro variable.
@jaiganesh wrote:
Retain Keyword (...) what would be it's alternative for Macro to do incremental addition
Hello @jaiganesh,
The primary purpose of the RETAIN statement in the DATA step is to prevent certain variables from being reset to missing at the beginning of a new iteration of the DATA step (implied loop).
In a SAS macro:
Example:
%macro test;
%let s=0;
%do i=20 %to 40 %by 10;
%let s=%eval(&s+&i);
%end;
%put &=s; /* result: 90 */
%mend test;
%test
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.