Good day everyone, I'm trying to write a code to automaticly group a variable in predefined buckets. In a last step I want to name the value (bucket name) based on the loop number, but somehow I'm not able to do this. The code of this last step is as follows: Data Want;
set Have;
/* If the observation has no bucket yet proceed to actions */
IF &Bucket.='' THEN DO;
/* Go through as many loops as there are buckets */
DO i=1 TO (2+(&MinValue.+&MaxValue.)/&Step.)-2;
/* If the value is > the minimum value of the bucket and <= the max value, then this should be the bucket*/
IF &Value. > &MinValue.+(i-1)*&Step. AND &Value. <= &MinValue.+ i*&Step. THEN
DO; /* If the bucket number is < 10 use 00 as a prefix, <100 use 0 as a prefix and otherwise use no prefix */
IF i + 1 < 10 THEN &Bucket.= "00%SYSEVALF(i+1). > %SYSEVALF(&MinValue.+(i-1)*&Step.) and <= %SYSEVALF(&MinValue.+i*&Step.)";
IF i + 1 >= 10 and i+1 < 100 THEN &Bucket.= "0%SYSEVALF(i+1). > %SYSEVALF(&MinValue.+(i-1)*&Step.) and <= %SYSEVALF(&MinValue.+i*&Step.)";
IF i + 1 >= 100 THEN &Bucket.= "%SYSEVALF(i+1). > %SYSEVALF(&MinValue.+(i-1)*&Step.) and <= %SYSEVALF(&MinValue.+i*&Step.)";
END;
END;
END;
run; For example: "00%SYSEVALF(&i.+1). > %SYSEVALF(&MinValue.+(&i.-1)*&Step.) and <= %SYSEVALF(&MinValue.+&i.*&Step.)"; Should result in: "002. > 0 and <= 10" if &Value. equals a number between 0 and 10. However SAS doesn't treat "i" as a numeric value in the generation of the result, but as the character i. So the %SYSEVALF() function doesn't work.: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: i+1 SAS does treat "i" as a numeric operand in the prior IF statement. I'm confused. Is there a solution for this? Regards, Maxim
... View more