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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 16307 views
  • 1 like
  • 4 in conversation