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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1657 views
  • 0 likes
  • 2 in conversation