Sometimes, we do need that macro variable has only numeric value.
We can use %EVAL to judge if the string is numeric value.
* Sample;
%let mv=1+a;
%let a=%eval(%scan(&mv, 1, +));
%let b=%eval(%scan(&mv, 2, +)); * Error occurs;
Independent SAS Consultant (https://github.com/sasrunner)
Oakville, ON, Canada
Certified SAS Base/Advanced Programmer
Certified Data Integration Developer for SAS
Certified Platform Administrator for SAS
Certified Visual Business Analyst for SAS
SAS Certified Associate: Programming Fundamentals Using SAS Viya
SAS Certified Specialist: Intermediate Programming Using SAS Viya
* Sample;
%let mv=1+a;
%let a=%eval(%scan(&mv, 1, +));
%let b=%eval(%scan(&mv, 2, +)); * Error occurs;
Stop it.
In SAS 9, we can use the function COMPARE. With the modifiers ("i", "l", ":"), we can handle the string comparison easily.
* COMPARE function Demo;
data _null_;
var = " This is test";
if left(upcase(var)) =: 'THIS' then put "Matched (1)";
if compare(var, 'THIS', 'il:') = 0 then put "Matched (2)";
run;
data _null_;
input;
line = prxchange('s/\b*(\w+)\b*/A/', -1, _infile_);
count = count(line, 'A');
put count=;
cards;
this is a test
;
%macro test(a);
%let b=2;
%put 1> a is "&a" and b is "&b";
data _null_;
put "2> a is '&a' and b is '&b'";
call symput('b', '3');
run;
%put 3> a is "&a" and b is "&b";
%mend;
* Standard Type;
%test(1)
* Output:
1> a is "1" and b is "2"
2> a is '1' and b is '2'
3> a is "1" and b is "3"
;
* CALL EXECUTE Type;
data _null_;
call execute('%test(1)');
run;
* Output:
1> a is "1" and b is "2"
3> a is "1" and b is "2"
2> a is '1' and b is '2'
;