Hello,
I am getting the below error code on var2. Any help is greatly appreciated!
ERROR: Overflow has occurred; evaluation is terminated.
%macro test
(_arg
);
%sysevalf(%superq(&_arg.)=,boolean)
%mend;
%macro test1;
%let var1 =32Z7905;
%let var2 =32D7905;
%do jj=1 %to 2;
%if %test(var&jj.)=0 %then %put IT WORKED &jj.;
%end;
%mend;
%test1;
Hi,
I really ike this method for testing for blank. It's the method from:
http://changchung.com/download/022-2009.pdf
Unfortunately, %SYSEVALF() can handle both numeric values and text values, so when you pass it a value, it decides whether the value is a number or text, based on something guessing rules.
%SYSEVALF() knows about exponential notation, and in the macro language 3D2 means 3*10**2, same as 3E2.
78 %put %sysevalf(3D2+1); 301
So when you pass your test macro 32D7905, %sysevalf overflows because it sees a very large number, 32*10**7905.
I think it would be better to have functions %EvalC and %EvalN which would only work with character / numeric arguments. Please see ballot item I proposed:
https://communities.sas.com/t5/SASware-Ballot-Ideas/New-macro-functions-EvalC-and-EvalN/idi-p/266134
For the current situation, one hack is to add some constant text that will force %sysevalf to treat the value as text rather than numeric, e.g.:
33 %macro test(_arg)/des="check if _arg is null/only white space";
34 %sysevalf(Q%superq(&_arg.)=Q,boolean)
35 %mend;
36 %let var1=32D7905;
37 %put %test(var1);
0
So adding the letter Q forces %sysevalf() to see a text value, even when the value of &&&arg is numeric. But I don't really like that hack. I also don't like adding double quote marks, e.g. %sysevalf("%superq(&_arg.)" = "",boolean).
--Q.
It helps if you take a minute to explain your question and problem. Include the log and error message as well.
Is your macro test supposed to check for missing values or if a macro variable is defined?
Also, check the parameters for SUPERQ
%SUPERQ(argument)
Required Argument
argument
is the name of a macro variable with no leading ampersand or a text expression that produces the name of a macro variable with no leading ampersand.
Hi Reeza,
I am trying to loop through a list of macro variables and verify the aren't missing. The problem I am having is it works for almost any other string. If I take the D out of var2 it also works, but other alphas don't cuase an issue. Below is the log. Thank you for your time. 🙂
1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='Program1';
4 %LET _CLIENTPROJECTPATH=XXXXX
5 %LET _CLIENTPROJECTNAME=’test.egp';
6
%LET _SASPROGRAMFILE=;
7
8 ODS _ALL_ CLOSE;
9 OPTIONS DEV=ACTIVEX;
NOTE: Procedures may not support all options or statements for all devices. For details, see the documentation for each procedure.
10 ODS LISTING GPATH=&sasworklocation;
11 FILENAME EGHTML TEMP;
12 ODS HTML(ID=EGHTML) FILE=EGHTML ENCODING='utf-8' STYLE=Analysis
12 ! STYLESHEET=(URL="file:///C:/Program%20Files/SAS/SharedFiles(32)/BIClientStyles/4.2/Analysis.css")
12 ! ATTRIBUTES=("CODEBASE"="http://www2.sas.com/codebase/graph/v92/sasgraph.exe#version=9,2") NOGTITLE NOGFOOTNOTE
12 ! GPATH=&sasworklocation;
NOTE: Writing HTML(EGHTML) Body file: EGHTML
13
14 %macro test
15 (_arg
16 )
17 /
18 des="check if _arg is null/only white space"
19 ;
20 %sysevalf(%superq(&_arg.)=,boolean)
21 %mend;
22
23 %macro test1;
24
25 %let var1 =32Z7905;
26 %let var2 =32D7905;
27
28 %do jj=1 %to 2;
29 %if %test(var&jj.)=0 %then %put IT WORKED &jj.;
30 %end;
31
32 %mend;
33
34 %test1;
IT WORKED 1
ERROR: Overflow has occurred; evaluation is terminated.
ERROR: The macro TEST will stop executing.
35
Hi,
I really ike this method for testing for blank. It's the method from:
http://changchung.com/download/022-2009.pdf
Unfortunately, %SYSEVALF() can handle both numeric values and text values, so when you pass it a value, it decides whether the value is a number or text, based on something guessing rules.
%SYSEVALF() knows about exponential notation, and in the macro language 3D2 means 3*10**2, same as 3E2.
78 %put %sysevalf(3D2+1); 301
So when you pass your test macro 32D7905, %sysevalf overflows because it sees a very large number, 32*10**7905.
I think it would be better to have functions %EvalC and %EvalN which would only work with character / numeric arguments. Please see ballot item I proposed:
https://communities.sas.com/t5/SASware-Ballot-Ideas/New-macro-functions-EvalC-and-EvalN/idi-p/266134
For the current situation, one hack is to add some constant text that will force %sysevalf to treat the value as text rather than numeric, e.g.:
33 %macro test(_arg)/des="check if _arg is null/only white space";
34 %sysevalf(Q%superq(&_arg.)=Q,boolean)
35 %mend;
36 %let var1=32D7905;
37 %put %test(var1);
0
So adding the letter Q forces %sysevalf() to see a text value, even when the value of &&&arg is numeric. But I don't really like that hack. I also don't like adding double quote marks, e.g. %sysevalf("%superq(&_arg.)" = "",boolean).
--Q.
Thanks a bunch @Quentin!
If you're trying to determine if a macro variable exists wouldn't %SYMEXIST be the way to do so?
@Reeza it's not checking whether a macro variable exists; it's checking if a macro variable (that exists) has a value. That is, checking that the macro variable is blank (or not).
(Chung & King's paper goes into nice detail, defining the difference between checking for %isBlank and %isNull, both of which differ from %SYMEXIST)
Sorry @Peter_C, I don't understand your question.
The proposed ballot suggests we have %EvalN and %EvalC. Both would do logical evaluation. %EvalN would do numeric comparisons, and %EvalC would do character comparisons.
So %EvalN(1e2=100) would return true, but %EvalC(1e2=100) would be false.
%EvalN(10>5) would be true, but %EvalC(10>5) would be false.
Point being that currently, %EVAL and %SYSEVALF both have to do some guessing (by different rules) to figure out if the arguments should be interpreted as text or numbers. And that guessing often leads to surprises (for those who don't know the rules that are used to guess), or in this case an overflow, when SAS guesses a type which is different than the programmer intended.
On a related, point, even in the data step language, I'm not sure I really like that the CAT functions are happy with a numeric argument or character argument. It's not really a problem, since in the data step language there is explicit typing. But when people use CAT functions in the macro setting, they are often supriserd that sysfunc(CATX()) will get rid of leading zeroes on a number, and again, it's the same guessing problem, where CATX() has guessed that the argument is numeric rather than text.
79 %put %sysfunc(catx(|,001,002,003)); 1|2|3
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.