BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi all,

I'm hoping that you can help me to try and get this right.

I am trying to pass a piece of text into a macro as a macro parameter, but I keep getting

ERROR: Literal contains unmatched quote.
ERROR: The macro SQL_INSERT will stop executing.

The call macro call is :

%sql_insert(proj_name=&mvar_projectname,
idd=&mvar_id,
dt=&mvar_changed,
rq="&mvar_requirements",
category=&mvar_applicationcategory_k);

The macro variable is a variable length text paragraph that may contain commas, single/ double quotes, & symbols and unmatched quotes and parenthesis.

So, I have tried numerous quoting methods to no avail, like enclosing &mvar_requirements in %str()...etc. Is there a method to cover all symbols?

Hope someone can help.

Thanks in advance.
3 REPLIES 3
DanielSantos
Barite | Level 11
Hi.

Well, that depends on what your trying to quote.

see: http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001072333.htm

for macro quotting functions.

Greetings from Portugal.

Daniel Santos at www.cgd.pt
Russ_SAS
SAS Employee
Try using %SUPERQ around the macro variable that is causing the problem, for example:

%sql_insert(proj_name=%superq(mvar_projectname),

It catches everything. Notice there is no & in front of the macro variable when using %SUPERQ.
LeonidBatkhan
Lapis Lazuli | Level 10

Depending on what characters you want to pass as a macro parameter value, you might need to use different SAS macro functions that provide "character masking". These macro functions are collectively called macro quoting functions. There are 7 of them, each has its own set of characters they mask, and the sets of those characters overlap between them. They also differ by their timing: A) macro compilation; or B) macro execution. You use macro compilation functions to mask characters in a string constants not containing & % or mnemonics (GT EQ OR AND etc). And you use macro execution functions otherwise.

 

Here are the 7 macro quoting functions:

A) Work at macro compilation

%STR() and %NRSTR()

 

B) Work at macro execution

%QUOTE() and %NRQUOTE(), %BQUOTE() and %NRBQUOTE(), and %SUPERQ().

 

I use "pass them inside the box" analogy to explain how they work in my recent blog post Passing comma-delimited values into SAS macros and macro functions.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 19802 views
  • 1 like
  • 4 in conversation