BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SeaMoon_168
Quartz | Level 8

I want to filter the data based on a where statement. The code is quite simple.

data sample;
set total;
where var = 1;
run;

However, I got the wrong message

ERROR: WHERE clause operator requires compatible variables.

I check var is numeric variable

Please help me figure out this issue. Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@SeaMoon_168 wrote:

I want to filter the data based on a where statement. The code is quite simple.

data sample;
set total;
where var = 1;
run;

However, I got the wrong message

ERROR: WHERE clause operator requires compatible variables.

I check var is numeric variable

Please help me figure out this issue. Thanks


I doubt that SAS is wrong here.

 

Make sure you checked the right TOTAL dataset.  Single level names normally mean WORK datasets.  But if you defined a USER libref or used the USER system option to select some other libref to use for one character names then SAS might.  Because of the error with the WHERE statement the SAS log will not help you since it will not show what actual dataset it attempted to read from.

 

Also check if TOTAL is a VIEW instead of a dataset.  In that case it might be using a WHERE statement (or WHERE= dataset option) that references some other variable and that is the source of the error.  Although that would normally provide more information.

59   data want ;
60    set class_v;
ERROR: Variable var has been defined as both character and numeric.
ERROR: WHERE clause operator requires compatible variables.
ERROR: Failure loading view WORK.CLASS_V.VIEW.
       Error detected during View Load request.
61    where name='Alfred';
62   run;

View solution in original post

2 REPLIES 2
Kathryn_SAS
SAS Employee

Have you tried:

where var='1';

Can you send a PROC CONTENTS of the Total data set?

proc contents data=total;
run;
Tom
Super User Tom
Super User

@SeaMoon_168 wrote:

I want to filter the data based on a where statement. The code is quite simple.

data sample;
set total;
where var = 1;
run;

However, I got the wrong message

ERROR: WHERE clause operator requires compatible variables.

I check var is numeric variable

Please help me figure out this issue. Thanks


I doubt that SAS is wrong here.

 

Make sure you checked the right TOTAL dataset.  Single level names normally mean WORK datasets.  But if you defined a USER libref or used the USER system option to select some other libref to use for one character names then SAS might.  Because of the error with the WHERE statement the SAS log will not help you since it will not show what actual dataset it attempted to read from.

 

Also check if TOTAL is a VIEW instead of a dataset.  In that case it might be using a WHERE statement (or WHERE= dataset option) that references some other variable and that is the source of the error.  Although that would normally provide more information.

59   data want ;
60    set class_v;
ERROR: Variable var has been defined as both character and numeric.
ERROR: WHERE clause operator requires compatible variables.
ERROR: Failure loading view WORK.CLASS_V.VIEW.
       Error detected during View Load request.
61    where name='Alfred';
62   run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2 replies
  • 446 views
  • 0 likes
  • 3 in conversation