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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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