BookmarkSubscribeRSS Feed
roberthembree
Calcite | Level 5

Pretty much the title. I think I found a bug in SAS macros. I found the cause of my problem but would like to share my findings with the developers. The closest I could get was posting here or contacting Techincal support. As far as I could tell they have no ability to address this type of issue so here I am. 

The script below shows how to create the bug and what its effects are. 

/* this will compile just fine */
%macro macA();
    %local a;
    %let a=1;
    proc print data=sashelp.cars;
    run;
%mend macA;

/* this will compile just fine */
%macro macB();
    %local b /* i forget the semicolon */
    %macA();
    proc print data=sashelp.air;
    run;
%mend;

/* this will give an error when I run it*/
%macB();

/* now no matter what you do, you can no longer recompile the macro %maca when you want to change it. It will return the error
ERROR: The macro MACA is still executing and cannot be redefined.
ERROR: A dummy macro will be compiled
*/
/* goahead try it */
%macro macA();
    %local a;
    %let a=1;
    proc print data=sashelp.cars;
    run;
%mend macA;

/* this will compile thought */
%macro macc();
    %local a;
    %let a=1;
    proc print data=sashelp.cars;
    run;
%mend macc;

/* you can still execute code, no problem, despite the macro supposedly still running but you can't recompile maca at this point. */ proc print data=sashelp.company; run;



Since I know this will be asked:

NOTE: Copyright (c) 2016 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) Proprietary Software 9.4 (TS1M7)
      Licensed to ______________________________
NOTE: This session is executing on the X64_10PRO  platform.



NOTE: Analytical products:

      SAS/STAT 15.2
      SAS/ETS 15.2
      SAS/IML 15.2
      SAS/QC 15.2

NOTE: Additional host information:

 X64_10PRO WIN 10.0.18362  Workstation

NOTE: SAS initialization used:
      real time           1.64 seconds
      cpu time            1.13 seconds

 

1 REPLY 1
ballardw
Super User

Tech support is who you contact to report any issues with SAS.

 

Don't expect incorrect syntax to be treated as a "bug" though.

 

Incorrect macro syntax that causes issues generally are resolved by 1) shutting down SAS and 2) fixing the syntax before rerunning the code.

 

Since you have %macA() in a %local statement if the macro resolves to anything that might be considered a valid list of names it works just fine.

%macro macA();
     var1 var2 var
%mend macA;

/* this will compile just fine */
%macro macB();
    %local b /* i forget the semicolon */
    %macA();
    proc print data=sashelp.class;
    run;
%mend;

%macB();

Are you sure that you mean recompile MacA? There would be no reason to, MacB is the culprit. MacB is still running and you can't compile it.

 

If running the code interactively this should cancel the running macros and allow recompiling:

%macro dummy;
%abort cancel;
%mend;
%dummy 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 873 views
  • 2 likes
  • 2 in conversation