BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Macro
Obsidian | Level 7

I use following to create a macro variable pattern so that it equals to %vs%:

%let pattern=%nrstr(%vs%);

%put pattern =&pattern;

But SAS gives error and warning:

WARNING: The quoted string currently being processed has become more than 262 characters long.  You might have unbalanced quotation marks.

How to achieve the desired result?


1 ACCEPTED SOLUTION

Accepted Solutions
FriedEgg
SAS Employee

The real issue is the second %.  The way %nrstr works, as vs% it will assume you are masking the ) sign on %nrstr(%vs%) and thus leave you with open code.

You could do any of the following:

%let pattern=%nrstr(%vs% );

%let pattern=%nrstr(%vs%%);

%let pattern=%nrstr(%%vs%%);

I prefer the last one...

View solution in original post

6 REPLIES 6
FriedEgg
SAS Employee

%let pattern=%nrstr(%%vs%%);

%put pattern=&pattern.;

pattern=%vs%

Macro
Obsidian | Level 7

Note that %nrstr() will mask % sign, then why do we need doulbe percent sign like %% to achieve a %??

FriedEgg
SAS Employee

The real issue is the second %.  The way %nrstr works, as vs% it will assume you are masking the ) sign on %nrstr(%vs%) and thus leave you with open code.

You could do any of the following:

%let pattern=%nrstr(%vs% );

%let pattern=%nrstr(%vs%%);

%let pattern=%nrstr(%%vs%%);

I prefer the last one...

Macro
Obsidian | Level 7

Thanks very much, very good explanation.

Macro
Obsidian | Level 7

Also why do we need a dot after &pattern?

FriedEgg
SAS Employee

You do not "need" it.  You could just consider it my personal preference for coding style.

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 6 replies
  • 4546 views
  • 0 likes
  • 2 in conversation