0

I am trying to create a macro with help option also like below:

%macro now(gg,datas); 

%if &gg=help %then  %do
%put; 
%put %str(hello);
%goto exit;
%end;
proc print data=&datas; run; 
  %mend; 

So when I call the macro with help

%now(help)

the following should be printed

hello 

in the log, but instead it doesnt do anything. What is wrong in this code?

user3658367
  • 641
  • 1
  • 14
  • 30
  • 1
    You may want to consider switching to use keyword parameters instead of positional parameters. As written, to call the macro without invoking the help mode, you would need to code `%now(,sashelp.shoes)` note the comma at the beginning, to give the gg parameter a null value. This would quickly become annoying to remember. With keyword parameters, you could call with `%ow(datas=sashelp.shoes)`. Actually, even though it's defined with positional parameters you can still call with keyword parameters. But I think better to define with keyword parameters. – Quentin Mar 24 '16 at 21:24

1 Answers1

2

You're missing a semicolon after the %do, and you've referred to a label called exit in your %goto statement which doesn't exist. These errors prevent the macro from being compiled, so when you attempt to call it, SAS does nothing (apart from generating a warning message in the log, unless you've disabled those).

The following should work as you expect:

%macro now(gg,datas); 

%if &gg=help %then  %do;
%put; 
%put %str(hello);
%goto exit;
%end;
proc print data=&datas; run; 
%exit:
  %mend; 

  %now(help)

I would suggest using %return for this sort of thing rather than %goto - you get the same sort of functionality without having to define labels and worry so much about the flow of your macro.

user667489
  • 9,501
  • 2
  • 24
  • 35