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.

 

 

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: 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.

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: 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.

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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