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?
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...
%let pattern=%nrstr(%%vs%%);
%put pattern=&pattern.;
pattern=%vs%
Note that %nrstr() will mask % sign, then why do we need doulbe percent sign like %% to achieve a %??
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...
Thanks very much, very good explanation.
Also why do we need a dot after &pattern?
You do not "need" it. You could just consider it my personal preference for coding style.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.