DATA Step, Macro, Functions and more

Someone know why SAS do that?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 144
Accepted Solution

Someone know why SAS do that?

Hi everyone,

 

In a macro I concatenate multiple levels. Seems that one of thats levels have a "%", as a separator i use "#" character and I get differents outputs depending on if I put or not " ".

 

Here an example

%let var=Test;
%let array=%;
%put &array.#&var.;
%#Test#Test
%put &array.# &var.;
%# Test
%put &array. #&var.;
% #Test #Test

Someone know Why this odd performance? It seems a strange performance that is not presented when there is not the "%"

 

Thanks

 

 

 


Accepted Solutions
Solution
‎06-08-2016 08:37 AM
Super Contributor
Posts: 439

Re: Someone know why SAS do that?

[ Edited ]
Posted in reply to arodriguez

Hi @arodriguez_syntaxfs_com,

 

Once you have come to gripsd with th emacro facility this behaviour will no longer seem strange. The % sign is what's called a type 3 macro trigger. It has special meaning for the macro facility and will throw things off if not properly stripped from that meaning.

 

Try coding 

 

%let array=%nrbquote(%);

and your code will run a lot better.  (edited from %nrstr(%%) to %nrbquote(%) which is even better)

 

For background I suggest you read up on macro quoting, an advanced subject indeed. But there are many good resources om the web.

 

Hope this helps,

- Jan.

View solution in original post


All Replies
Solution
‎06-08-2016 08:37 AM
Super Contributor
Posts: 439

Re: Someone know why SAS do that?

[ Edited ]
Posted in reply to arodriguez

Hi @arodriguez_syntaxfs_com,

 

Once you have come to gripsd with th emacro facility this behaviour will no longer seem strange. The % sign is what's called a type 3 macro trigger. It has special meaning for the macro facility and will throw things off if not properly stripped from that meaning.

 

Try coding 

 

%let array=%nrbquote(%);

and your code will run a lot better.  (edited from %nrstr(%%) to %nrbquote(%) which is even better)

 

For background I suggest you read up on macro quoting, an advanced subject indeed. But there are many good resources om the web.

 

Hope this helps,

- Jan.

Super User
Super User
Posts: 7,942

Re: Someone know why SAS do that?

Posted in reply to arodriguez

The question really is why are you doing that, are you trying to make unreadable code?

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 268 views
  • 0 likes
  • 3 in conversation