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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.