Hi,
I want to allocate this value to a macro variable but am getting an error message (using SAS EG 4.1):
%let WarnTxt1= Warning - This component has a low value of Cronbach's Alpha (less than 0.7);
I imagine this could be due to the length of the string and/or certain characters. Is there a way to make SAS accept this string?
The warning I am getting is " The quoted string currently being processed has become more than 262 characters long. You may have unbalanced quotation marks."
Thanks.
VD
Message was edited by: Vikas Dhawan
You have to mask the quote. e.g.:
%let WarnTxt1= Warning - This component has a low value of %nrbquote(Cronbach's) Alpha (less than 0.7);
(Note: I originally had included the following comment: "That works on 9.3, but I seem to recall that macro variable names couldn't end with a number in older versions of SAS.". Too early in the morning! Character formats can't end in a number .. macro variables can).
Arthur ,
I would like to use %str() which is designed for it.
%let WarnTxt1=%str(Warning - This component has a low value of Cronbach%'s Alpha %(less than 0.7%) );
%put WARNING: &warntxt1 ;
Ksharp
Try adding double quotes around the verbage...
%let WarnTxt1= "Warning - This component has a low value of Cronbach's Alpha (less than 0.7)";
Yes, the "mess" that is SAS macro quoting and the lack of obviousness that is choosing the right masking macro function.
First there was %NR/STR, than %NR/QUOTE, after that %NR/BQUOTE was introduced, and at last %SUPER...
And each one has one or more particular set of features, being:
- Compile time, and runtime execution:
Some operate at compile time, while the others only evaluate at runtime (nothing happens at compile time their treated as text).
- percent and ampersand masking:
Easy to identify, every* macro function starting with %NR will mask the % and & preventing the resolve of macro variables/functions.
- unmatched single quotes, double quotes and parentheses masking:
Actually all quoting functions are capable of masking unmatched single/double quotes and parentheses, but some mask them char by char while other do this by pair unless you explicitly identify the unmatched pairs prefixing the char with a percent sign (%).
Every* functions starting with the form %NRB* or %B* do not need to identify unmatched pairs.
* there's actually a macro quoting function that doesn't follow the rule, %SUPER, which (as the name says) is the super-mega-power-thing on macro quoting.
So with that, and knowing that %STR is a compile time function and %NRBQUOTE is a runtime one.
%STR will not mask percent and ampersand (no %NR prefix) and will require to identify unmatched pairs (no %B* prefix).
%NRBQUOTE will mask percent and ampersand (%NR prefix) and will not require to identify unmatched pairs (%NRB* prefix).
For your particular case, % and & masking is not need, and the moment of function evaluation is pretty much irrelevant (compile/runtime).
So, since you have a single unmatched quote, it's pretty much a matter of choosing If you want to identify it or not.
From there, you may choose one of three functions. %STR or %QUOTE, which both require the % before the single quote and differ only on execution time (compile/runtime). Or %BQUOTE, which will not require to identify the unmatched quote, and is evaluated at runtime.
All suggestions above are correct, as they will solve VD's single quote problem. That being said...
@Artur, %NRBQUOTE is actually more than it's needed as there is no & or % to mask, %BQUOTE is just enough.
@Ksharp, for %STR there is no need to mask matched pairs(), just the unmatched single quote.
Cheers from Portugal.
Daniel Santos @ www.cgd.pt
Thank you all for your replies, much appreciated!
%NRBQUOTE and %BQUOTE seem to work fine. But only in Base SAS (9.1). Somehow they are not working in EG(4.1) for me.
However I managed to make it work using use call symputx - perhaps not the most neat solution!
data _null_; set in1;
format Txt1 $76. ;
Txt1="Warning - This component has a low value of Cronbach's Alpha (less than 0.7)";
call symputx("WarnTxt1",Txt1);
end;
Cheers.
VD
@Daniel Santos
Yes. I know it too. just for the safe .
Ksharp
Hi Daniel,
I really like your nutshell style of explantation. Those macro quote facilities are just as annoying to me.
Haikuo
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.