I am getting the following error when I use below code. Can anyone help me debug this.
code...
%if &colloff = 084 %then %do;
%if &qtr = 2012-11TestNS %then %do;
libname librf "I:\Valuation\2012-12\ALICO\ProdLM\Programs\Standard\DACRollFrwd\SASLib";
%end;
%else %if &qtr = "2013-02Prod" %then %do;
libname librf "I:\Valuation\2013-01\ALICO\ProdLM\Programs\Standard\DACRollFrwd\SASLib";
%end;
%end;
log..
SYMBOLGEN: Macro variable COLLOFF resolves to 084
SYMBOLGEN: Macro variable QTR resolves to 2012-11TestNS
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand
is required. The condition was: %BQUOTE(&qtr) = 2012-11TestNS
is required. The condition was: %BQUOTE(&qtr) = 2012-11TestNS
is required. The condition was: %BQUOTE(&qtr) = 2012-11TestNS
ERROR: The macro MASTER will stop executing.
ERROR: The macro MASTER will stop executing.
ERROR: The macro MASTER will stop executing.
801 endsas;
Hi,
Your are correct that it's a quoting problem. (Looks like you added %Bquote when you called the macro. )
The macro language thinks the dash in 2012-11TestNS is a subtraction sign, and tries to do subtraction with the character values, and chokes. So you need to hide (aka mask aka quote) the values.
Suggest you try:
%if %superq(qtr)=%str(2012-11TestNS) %then %do;
(and same for the second %if, and remove the double quotes from the second %if)
So %superq() hides a dash which results from resolving &qtr at macro execution time, and %str() hides the dash that you can see in 2012-11TestNS at macro compile time.
HTH,
--Q.
Hi,
Your are correct that it's a quoting problem. (Looks like you added %Bquote when you called the macro. )
The macro language thinks the dash in 2012-11TestNS is a subtraction sign, and tries to do subtraction with the character values, and chokes. So you need to hide (aka mask aka quote) the values.
Suggest you try:
%if %superq(qtr)=%str(2012-11TestNS) %then %do;
(and same for the second %if, and remove the double quotes from the second %if)
So %superq() hides a dash which results from resolving &qtr at macro execution time, and %str() hides the dash that you can see in 2012-11TestNS at macro compile time.
HTH,
--Q.
ah.. thank you so much.. it works..
can i make it as below.. if in case my variable resolves in upper case or lowercase?
%if %superq(qtr)=%str(%upcase(2012-11TESTNS)) %then %do;
I think for that you don't need to upcase the right-hand side (because you already typed it in upcase), you need to upcase the left side. Intead of %superq, you can use %qupcase. Something like:
4 %macro comp(qtr=); 5 %if %qupcase(&qtr) = %str(2012-20122TESTNS) %then %put Match; 6 %else %put NO MATCH; 7 %mend comp; 8 9 %comp(qtr=2012-20122TESTNS) Match 10 %comp(qtr=2012-20122testns) Match 11 %comp(qtr=9999testns) NO MATCH
Note that with %qupcase, you need the & on &qtr.
--Q.
Thank you.
I was just curious and used %superq in place of %qupcase and got the below error. Can you explain me why the below did not work?
31 %macro comp(qtr=);
32 %if %superq(&qtr) = %str(2012-12TESTNS) %then %put Match;
33 %else %put NO MATCH;
34 %mend comp;
35
36 %comp(qtr=2012-12TESTNS)
ERROR: Invalid symbolic variable name 2012-12TESTNS.
NO MATCH
Hi,
One oddity of %superq is that the argument is the name of a macro variable, without the & sign in front.
7 %macro comp(qtr=); 8 %if %superq(qtr) = %str(2012-12TESTNS) %then %put Match; 9 %else %put NO MATCH; 10 %mend comp; 11 12 %comp(qtr=2012-12TESTNS) Match 13 %comp(qtr=2012-12testns) NO MATCH
An alternative to using %qupcase would be to %upcase the value in a separated %let statement.
16 %macro comp(qtr=); 17 %let qtr=%upcase(&qtr); 18 %if %superq(qtr) = %str(2012-12TESTNS) %then %put Match; 19 %else %put NO MATCH; 20 %mend comp; 21 22 %comp(qtr=2012-12TESTNS) Match 23 %comp(qtr=2012-12testns) Match
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.