@svasu611 wrote:
HI Team,
why my macro not create new variable.
data s;
set sashelp.class;
if name="Alice" then
new=1;
run;
%macro a;
data a;
set sashelp.class;
%if name="Alice" %then
%do;
new=1;
%end;
run;
%mend;
%a;
Thanks in Advance.
Because you completely misunderstand what the macro processor is, what it does, and when it does it.
The macro preprocessor is a sophisticated text generation engine that modifies code before it is fed to the SAS interpreter.
It only sees text, and the texts
name
and
"Alice"
(note the presence and non-presence of quotes, they are part of the text)
are not the same, so the code
new=1;
is not created by the macro, and can't be executed by the SAS interpreter.
Since you are a beginner, I strongly suggest you don't dabble with macros for the time being, and instead really learn how to work with the Base SAS code. Since macros generate dynamic code, it is essential to know what you create and what that will do in order to make proper use of the macro language.
Simple text replacement through macro variables is another thing, safe for beginners.