Hello team,
I have a Macro as below:
%MACRO a(text=);
%put %str(N)OTE: ¶m. &text.!;
%MEND a;
%MACRO b(param=);
%if %lowcase(¶m.) eq hello %then %a(text=Dear);
%MEND b;
%b(param=HelLO);
----
I am trying to define the components of this Macro for myself:
Is "a" in %Macro a name of the Macro?
Is (text) in a(text) a parameter for Macro a?
Is %put a Macro statement which writes the result of the Macro into the log?
Is %str a Macro statement which masks parentheses?
Are &Param and &Text a call to the parameters param and text?
Why do we have . and exclamation sign in this code: %put %str(N)OTE: ¶m. &text.!;?
Why difference did it make if enter (N)OTE as Note? Do we want to show the implementation of STR function?
Does SAS process the code line by line?
If you have more input about this piece of code, please explain it.
Respectfully,
Blue Sky
In the macro processor the . indicates the end of a macro variable name or "concatenate" sort of operator for a macro variable followed by other text in the macro language.
The ! is punctuation to display at the end the end of sentence.
You might see why the . is needed if you run:
%let text=ABC; %put Test 1: &text123; %put Test 2: &text.123;
The first %put generates an error because "text123" could be a valid macro variable name but not currently defined (most likely). The second tells SAS to place the digits "123" immediately after the value of the macro variable.
This is why when you use macro variables to reference libraries you see two . between the library reference and the data set name such as :
Proc print data=&maclib..&macdatasetname. The first dot ends the library name and the second dot is the typical separator between library and data set.
In the macro processor the . indicates the end of a macro variable name or "concatenate" sort of operator for a macro variable followed by other text in the macro language.
The ! is punctuation to display at the end the end of sentence.
You might see why the . is needed if you run:
%let text=ABC; %put Test 1: &text123; %put Test 2: &text.123;
The first %put generates an error because "text123" could be a valid macro variable name but not currently defined (most likely). The second tells SAS to place the digits "123" immediately after the value of the macro variable.
This is why when you use macro variables to reference libraries you see two . between the library reference and the data set name such as :
Proc print data=&maclib..&macdatasetname. The first dot ends the library name and the second dot is the typical separator between library and data set.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.