NOTE: Numeric values have been converted to character values at the places given by:
(Line):(Column).
254:30 254:40 254:53
NOTE: There were 29 observations read from the data set WORK.CASEOUT.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: CALL EXECUTE generated line.
1 + DATA qualify1; SET controls; WHERE (25-0 <= age <= 25+0) AND (gender
= "0"); case_age = 25; case_gender = "0"; SEED = RANUNI(0);
ERROR: WHERE clause operator requires compatible variables.
"25" is simply the youngest age in my data set, which ranges from 25 to 76. I do not understand why it gives the error that "where" needs a compatible variable. Both "age" and "gender" are numeric in my dataset. I double checked to make sure. I am not sure if the "NOTE" above it has somehow converted one of them in a character, and hence the mistake?
It's hard to see what's going on as you have posted your code and warnings / errors separately so we don't know where they are happening. Please post your complete SAS log including messages with the SAS statement at the start - OPTIONS MPRINT; - so we can see what the macro is doing.
Hello @Manol_Jovani
Your where clause "WHERE (25-0 <= age <= 25+0) AND (gender= "0");" is the cause of error.
Try changing (25-0 <= age <= 25+0) . I am giving a sample code below using sashelp.class.
In my example age is between 10 and 12. You can replace 10 with 25 and 12 with 76.
data test;
set sashelp.class(Rename=(sex=gender));
where (age between 10 and 12) and (gender="M");
run;
The message " ERROR: WHERE clause operator requires compatible variables" implies the variables and the values you are comparing with may not be of the same type (for example one may be a numeric and other may be of character types.) Please verify.
The message is very clear.
What you say is less clear: How can you say GENDER is numeric, and code GENDER="0" ?
Remove the quotes.
Hello @ChrisNZ
I am not saying that Gender is numeric or character. I tried to clarify what the error message was in my own way.
Under similar situation, I would find the type of my variables in the where clause.
> I am not saying that Gender is numeric or character.
Yes you are
"25" is simply the youngest age in my data set, which ranges from 25 to 76. I do not understand why it gives the error that "where" needs a compatible variable. Both "age" and "gender" are numeric in my dataset. I double checked to make sure. I am not sure if the "NOTE" above it has somehow converted one of them in a character, and hence the mistake?
> Under similar situation, I would find the type of my variables in the where clause.
I don't know what this means.
Did removing the quotes fix the error?
Did you have code that ran correctly before creating the macro? That should be first thing. The data problem you are having should have been identified/ resolved with the non-macro code debugging.
@Manol_Jovani wrote:
Yes, the code above the macro works fine, there is no problem there. Is that what you are asking?
No. I am asking if the part inside the macro, when tested without any macro coding, ran. The question about whether quotes are needed or not should have been resolved at that time before adding macros.
Messages about "conversion"
Numeric values have been converted to character values at the places given by: (Line):(Column).
is a warning that you are writing code incorrectly. That message says that you are doing something that treats a numeric variable as character. You may not know this yet, but numeric variables when converted to character typically do not create a value that works as you may expect.
Here is a very simple example of the incompatible "where" clause.
data example;; /* character value with digits*/ x='123'; /* numeric value*/ y=123; run; data result; set example; where x=y; run;
Caution: Writing macros without RUN statements ending Procedures or Data steps is also a "gotcha" just waiting to happen.
You can write macro code quite easily that incorrectly by-passes an "implied" run and have lines from a following procedure or data step thought as part of the current one running. This is extremely easy if one macro calls another. You can spend a LOT of time tracing down such odd seeming problems caused by this small bit. Ask me how I know😓
Which is why code you attempt to create inside a macro has to be made without macros and run correctly before ever adding a %macro/ %mend. around it.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.