Hello All, Need assistance with an issue I am unable to find a solution for. Below are the Macro and sample Data Step I have. %macro exception(finish);
%do i=%substr(&finish, %length(&finish), 1) %to %eval(%substr(&finish, %length(&finish), 1)+1);
%let i=%eval(&i+1);
%put %substr(&finish, 1, %eval(%length(&finish)-1))&i;
%end;
%mend;
/*Macro would increment the Tier by 1, the condition in DataStep is true*/
proc sql;
create table data_in (
STUDENT_NO NUM(8),
TEST_SCORE NUM(20),
TIER CHAR(50),
EXCEPTION_CD CHAR(10)
);
insert into data_in (STUDENT_NO, TEST_SCORE, TIER, EXCEPTION_CD)
values(1, 70, 'Tier_3', '')
values(2, 80, 'Tier_2', '8')
values(3, 90, 'Tier_1', '8')
values(4, 65, 'Tier_0', '')
;
quit;
data data_in;
set data_in;
select (EXCEPTION_CD);
when ('8') EXCEPTION_TIER = %exception(TIER);
otherwise EXCEPTION_TIER = TIER;
end;
run; Below is the LOG with Errors: 50 when ('8') EXCEPTION_TIER = %exception(TIER);
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
%substr(&finish, %length(&finish), 1)
ERROR: The %FROM value of the %DO I loop is invalid.
50 when ('8') EXCEPTION_TIER = %exception(TIER);
_
22
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, INPUT, PUT.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
R+1
ERROR: %EVAL function has no expression to evaluate, or %IF statement has no condition.
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro EXCEPTION will stop executing. The out I desire: STUDENT_NO TEST_SCORE TIER EXCEPTION_CD EXCEPTION_TIER 1 70 Tier_3 Tier_3 2 80 Tier_2 8 Tier_3 3 90 Tier_1 8 Tier_2 4 65 Tier_0 Tier_0 Any solution would be helpful. Thanks, RV.
... View more