BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I am trying to submit the following codes, but it always comes up with the error: ???

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: split-1
ERROR: The macro INFO will stop executing.


-------------------------------------------------------------------------------------------------



libname project 'F:\Courseinfo\fall2009\CS699\presentation';

%macro var_discret (var);

data pd_&var;
set project.pd_data_import (keep=&var status);
run;

proc sort data=pd_&var;
by &var;
run;

%macro info(split);

data _null_;
%let L_obs=%sysevalf(&split-1);
set pd_&var (firstobs=1 obs=&L_obs) end=lastobs;

if status=1 then count_yes+1;
else if status=0 then count_no+1;
if lastobs then do; p_yes=count_yes/&L_obs; p_no=count_no/&L_obs;entropy=-p_yes*log(p_yes)/log2-p_no*log(p_no)/log2;
call symput ('entropy_D1', trim(left(put(entropy,8.0)))); end;
run;

data _null_;
%let R_obs=%sysevalf(&split+1);
set pd_&var (firstobs=&R_obs obs=195) end=lastobs;

if status=1 then count_yes+1;
else if status=0 then count_no+1;
if lastobs then do; p_yes=count_yes/(196-&R_obs); p_no=count_no/(196-&R_obs);entropy=-p_yes*log(p_yes)/log2-p_no*log(p_no)/log2;
call symput ('entropy_D2', trim(left(put(entropy,8.0)))); end;
run;

%let info=%sysevalf((&L_obs/195)*&entropy_D1+((196-&R_obs)/195)*&entropy_D2);
%let previous_info=&info;
%mend;

%do split= 2 %to 194;
%info(split)
%if %sysevalf(&info lt &previous_info) %then %let final_split_pos_&var=&info;
%end;

%put "The final split point for variable &var is &split";
%mend;

%var_discret(MDVP_Fo)
1 REPLY 1
Flip
Fluorite | Level 6
You should be using %info(&split) not %info(split)

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 1 reply
  • 790 views
  • 0 likes
  • 2 in conversation