Macro quoting function Error.

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

Macro quoting function Error.

%let x=10;

%let y12=%bquote(data tp;c="&x";runSmiley Wink;

&y12

 

getting the below error after executing the above code:-

 

NOTE: Line generated by the macro variable "Y12".

29 ata tp;c="10";run;

_

386

_

200

ERROR 386-185: Expecting an arithmetic expression.

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.TP may be incomplete. When this step was stopped there were 0 observations and 1 variables.

WARNING: Data set WORK.TP was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.01 seconds

 

 


Accepted Solutions
Solution
‎01-29-2016 12:29 AM
Trusted Advisor
Posts: 1,116

Re: Macro quoting function Error.

[ Edited ]

@Chikku: In short, you should have submitted %UNQUOTE(&y12) rather than only &y12 to get rid of the so called "delta" characters introduced by %BQUOTE into macro variable Y12, before the resolved text is processed by the data step compiler. Alternatively, you could have used %STR instead of %BQUOTE, because the purpose of the macro quoting function in this place is to mask the semicolons (not the double quotation marks) at compile time, so that they are not interpreted as ending the %LET statement.

 

The error you observed is due to a delta character associated with the quotation marks, whereas the keyword "data" has been very well submitted to the data step compiler (including the "d"). This is shown clearly by the log messages ("DATA statement ..." etc.). It is just not printed correctly in the log because of a preceding delta character. The error messages are similar to those which also occur when you submit 

data tp;c=#;run;

  

However, if you submit 

ata tp;c="10";run;

the error messages are completely different.

 

I can write a bit more tomorrow (CET) or you can read the paper yourself which I know these "secrets" from:

Susan O’Connor: Secrets of Macro Quoting Functions - How and Why (NESUG 99)

 

@KurtBremser: The above paper says that the %PUT function, when applied to a macro variable reference such as &testmac, "convert[s] the delta characters to printable characters" (p. 4). They can be seen, however, in the log output of

%put _user_;

So, %put &testmac; does not fully reveal what "the macro variable contains."

View solution in original post


All Replies
Super User
Posts: 5,380

Re: Macro quoting function Error.

Why are you putting data step code into a macro variable?

Data never sleeps
Super User
Posts: 7,394

Re: Macro quoting function Error.

This is much easier to comprehend:

 

%let x=10;

%macro y12;
data tp;
c="&x";
run;
%mend;

%y12;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 29

Re: Macro quoting function Error.

thank you for the info.

 

But what i need is why it is failing,the reason behind the failure of the code.

 

regards.

Super User
Posts: 7,394

Re: Macro quoting function Error.

Interesting. The operation fails because of the quotes within the macro variable that is supposed to contain a complete data step.

%let x=10;

%let testmac=%bquote(data xxx;x=put(&x,2.);run;);

&testmac

works, while

%let x=10;

%let testmac=%bquote(data xxx;x="&x";run;);

&testmac

fails because of a "swallowed" character "d" from the word "data" when &testmac is simply written to SAS code. The same happens with single quotes.

OTOH,

%put &testmac;

will show that the macro variable contains what is expected.

 

Eagerly waiting for an explanation for this.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,686

Re: Macro quoting function Error.

Sorry, am not seeing the point, why not just use Base SAS:

data tp;
  c="10";
run;

There really is 99% of the time, no need to resort to macro language.

Solution
‎01-29-2016 12:29 AM
Trusted Advisor
Posts: 1,116

Re: Macro quoting function Error.

[ Edited ]

@Chikku: In short, you should have submitted %UNQUOTE(&y12) rather than only &y12 to get rid of the so called "delta" characters introduced by %BQUOTE into macro variable Y12, before the resolved text is processed by the data step compiler. Alternatively, you could have used %STR instead of %BQUOTE, because the purpose of the macro quoting function in this place is to mask the semicolons (not the double quotation marks) at compile time, so that they are not interpreted as ending the %LET statement.

 

The error you observed is due to a delta character associated with the quotation marks, whereas the keyword "data" has been very well submitted to the data step compiler (including the "d"). This is shown clearly by the log messages ("DATA statement ..." etc.). It is just not printed correctly in the log because of a preceding delta character. The error messages are similar to those which also occur when you submit 

data tp;c=#;run;

  

However, if you submit 

ata tp;c="10";run;

the error messages are completely different.

 

I can write a bit more tomorrow (CET) or you can read the paper yourself which I know these "secrets" from:

Susan O’Connor: Secrets of Macro Quoting Functions - How and Why (NESUG 99)

 

@KurtBremser: The above paper says that the %PUT function, when applied to a macro variable reference such as &testmac, "convert[s] the delta characters to printable characters" (p. 4). They can be seen, however, in the log output of

%put _user_;

So, %put &testmac; does not fully reveal what "the macro variable contains."

Super User
Posts: 9,856

Re: Macro quoting function Error.

You need use macro quote function to mask the special character when you put it into LOG .

 

%let x=10;
%let y12=%bquote(data tp;c="&x";run;);
%put %bquote(&y12);
☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 448 views
  • 1 like
  • 6 in conversation