If we run the following loop in SAS (loop numbers 2,4,5,6,7,8,9, or any other specific strings), we will get strange SAS error message
%macro loop_bmd;
%local k j;
%let k=1;
%let visit="2:4:5:6:7:8:9";
%do %while (%scan(&visit, &k, %str(:)) ne);
%let j= %scan(&visit, &k, :);
%put &j;
%let k = %eval(&k + 1);
%end;
%mend loop_bmd;
%loop_bmd;
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: %scan(&visit, &k, :) ne ERROR: The condition in the %DO %WHILE loop, %scan(&visit, &k, :) ne, yielded an invalid or missing value, . The macro will stop executing.
The problem is because the following statement:
%let visit="2:4:5:6:7:8:9";
We should get rid of the quote marks.
%let visit=2:4:5:6:7:8:9;
The following code runs fine.
%macro loop_bmd;
%local k j;
%let k=1;
%let visit=2:4:5:6:7:8:9;
%do %while (%scan(&visit, &k, %str(:)) ne);
%let j= %scan(&visit, &k, :);
%put &j;
%let k = %eval(&k + 1);
%end;
%mend loop_bmd;
%loop_bmd;