BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

In answering another question, @Ksharp  pointed out that code like:

"%%foo"

will not trigger the macro processor to execute the macro FOO.  https://communities.sas.com/t5/SAS-Programming/warning-in-macro/m-p/895236/highlight/true#M353679

 

This was a surprise to me, and I think it is likely a word scanner / tokenization bug.  I'm not aware of any documented feature of the macro language that would explain this behavior.

 

In testing more, found some interesting results.  

 

The issue only seems to happen when there are an even number of consecutive macro triggers, i.e. %% or &% that appear inside of double quotes or parentheses.

 

I would expect all examples below to trigger the macro processor to execute the macro FOO.

 

Basic example:

%put %%Foo ;    *Does trigger macro processor ;
%put "%%Foo" ;   *Does NOT trigger macro processor ;

It's not a %PUT statement issue.  And it's not that %% is somehow resolving to %:

1    data want;
2      x="%%Foo" ;  *Does NOT trigger macro processor ;
3      put x= ;
4    run ;

x=%%Foo
NOTE: The data set WORK.WANT has 1 observations and 1 variables.

 

An odd number of % signs triggers macro processor, even does not:

%put "%Foo" ;    *Does trigger macro processor ;
%put "%%Foo" ;   *Does NOT trigger macro processor ;
%put "%%%Foo" ;  *Does trigger macro processor ;
%put "%%%%Foo" ; *Does NOT trigger macro processor ;

Parentheses can also cause the issue:

%put %length(%foo) ;   *Does trigger macro processor ;
%put %length(%%foo) ;  *Does NOT trigger macro processor ;

An ampersand followed by one or more percent signs seems to have the same effect:

%put &%Foo ;     *Does trigger macro processor ;
%put "&%Foo" ;   *Does NOT trigger macro processor ;

%put "%Foo" ;    *Does trigger macro processor ;
%put "&%Foo" ;   *Does NOT trigger macro processor ;
%put "&%%Foo" ;  *Does trigger macro processor ;
%put "&%%%Foo" ; *Does NOT trigger macro processor ;

data want;
  x="&%Foo" ;  *Does NOT trigger macro processor ;
  put x= ;
run ;

%put %length(&%foo) ;  *Does NOT trigger macro processor ;

 

I submitted the issue to tech support (CS0017798).  They confirmed the behavior, and have escalated to R&D for an explanation.

 

 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

I heard back from Tech Support.  They didn't provide any interesting insights or explanations, but they did confirm that this is a bug, and said they will be documenting it with a new problem note.  I asked them to share the URL after the note is published so that I can link to it from here.  But for now, I'll mark this as the accepted answer to close this out.

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

View solution in original post

1 REPLY 1
Quentin
Super User

I heard back from Tech Support.  They didn't provide any interesting insights or explanations, but they did confirm that this is a bug, and said they will be documenting it with a new problem note.  I asked them to share the URL after the note is published so that I can link to it from here.  But for now, I'll mark this as the accepted answer to close this out.

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

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
  • 703 views
  • 10 likes
  • 1 in conversation