In SAS, why cannot we write
let name = abc;
put "&name";
Why do we have to include the % sign like this:
%let name = abc;
%put &name;
Imagine I am writing the statements in the main body of the code, not inside a data step.
Also, is the second way of writing it same as:
%macro test;
%let name = abc;
%put &name;
%mend;
%let
and %put
are part of the SAS macro language. Macro language statements are (with one or two particular exceptions) prefixed by %
to tell the SAS macro parser to operate on them.
They do entirely different things from the non-%
version - except when it works out to the same thing. You can write put "&mvar.";
- as long as it's in a data step (As that's a data step statement). Macro commands/functions/statements are allowed in open code sometimes (and not in others).
Writing it inside an actual macro is more-or-less the same. There are scoping issues, though; &name
won't be available outside of that macro, unless it's been declared global.