Help using Base SAS procedures

MACRO

Reply
Regular Contributor
Posts: 161

MACRO

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;
Occasional Contributor
Posts: 18

Re: MACRO

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.
SAS Super FREQ
Posts: 8,868

Re: MACRO

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
Regular Contributor
Posts: 161

Re: MACRO

Posted in reply to Cynthia_sas
thanks for always helping
Regular Contributor
Posts: 165

Re: MACRO

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.
Regular Contributor
Posts: 241

Re: MACRO

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.
Ask a Question
Discussion stats
  • 5 replies
  • 153 views
  • 0 likes
  • 5 in conversation