BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
helloSAS
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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.


View solution in original post

6 REPLIES 6
Quentin
Super User

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.


helloSAS
Obsidian | Level 7

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;

Quentin
Super User

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.

helloSAS
Obsidian | Level 7

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

Quentin
Super User

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 3333 views
  • 4 likes
  • 2 in conversation