BookmarkSubscribeRSS Feed
R_A_G_
Calcite | Level 5
hello,

What is the difference in ending the macro TYPE1 Vs. TYPE2.
Thanks

TYPE1:
%macro tryit;
*%let dattype=ae;
%let dattype=demog;
*%let dattype=meds;
***********************;
%put data type is &dattype;
%mend tryit;
%tryit

TYPE2:
%macro tryit;
*%let dattype=ae;
%let dattype=demog;
*%let dattype=meds;
***********************;
%put data type is &dattype;
%mend;
%tryit;
5 REPLIES 5
SusieQ324
Fluorite | Level 6
Syntax-wise, I think you'll need to state the macro name in TYPE2 on your %mend statement. But other than that, invoking the macro is the same.
Cynthia_sas
Diamond | Level 26
Hi:
As the documentation says
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000206958.htm
-- repeating the macro name is not required, but is very useful for clarity, especially when a job might have more than 1 definition for a macro program inside.

cynthia
R_A_G_
Calcite | Level 5
thanks for always helping
RickM
Fluorite | Level 6
You don't really need the macro name in the %mend statement. It just helps you keep track of which macro you just ended. There is no difference between the two types.
chang_y_chung_hotmail_com
Obsidian | Level 7
In case you are asking if we should invoke a macro with or without a trailing semi-colon:



   %macro test;


      %let dattype=demog;


      %put data type is &dattype;


   %mend test;


 


   %*-- type1 --*;


   %test


 


   %*-- type2 --*;


   %test;





It depends. A macro invocation does not require a semi-colon, but anything that can signal the end of the invocation. Thus if your macro generates a complete statement including the statement ending semi-colon, then the type 2 style invocation results in an extra semi-colon. This is often OK, though, if the extra semi-colon, in the context, can be considered as a null statement and is ignored.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1716 views
  • 0 likes
  • 5 in conversation