DATA Step, Macro, Functions and more

How to create a macro variable equal to %vs%

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

How to create a macro variable equal to %vs%

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?



Accepted Solutions
Solution
‎10-27-2014 06:01 PM
Trusted Advisor
Posts: 1,301

Re: How to create a macro variable equal to %vs%

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


All Replies
Trusted Advisor
Posts: 1,301

Re: How to create a macro variable equal to %vs%

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

%put pattern=&pattern.;

pattern=%vs%

Contributor
Posts: 50

Re: How to create a macro variable equal to %vs%

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

Solution
‎10-27-2014 06:01 PM
Trusted Advisor
Posts: 1,301

Re: How to create a macro variable equal to %vs%

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

Contributor
Posts: 50

Re: How to create a macro variable equal to %vs%

Thanks very much, very good explanation.

Contributor
Posts: 50

Re: How to create a macro variable equal to %vs%

Also why do we need a dot after &pattern?

Trusted Advisor
Posts: 1,301

Re: How to create a macro variable equal to %vs%

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 241 views
  • 0 likes
  • 2 in conversation