DATA Step, Macro, Functions and more

Help with the Where clause proc print

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 130
Accepted Solution

Help with the Where clause proc print

Hi,

 

I am not sure why this would not work. Any suggestions? Thanks.

 

Libname Review'/folders/myfolders/Review' ;
Libname Learn'/folders/myfolders/Learn' ;  
Libname myformat'/folders/myfolders/sasuser.v94' ; 
Options fmtsearch=(myformat) ;

Proc Print data=learn.sales noobs ; 
	where Region eq ('North' AND Quantity lt 160) 
	OR Customer eq "Pet's are Us" ; /* Double "" because Pet's*/
run ; 

 I am getting the following error:

 69         Proc Print data=learn.sales noobs ;
 70         where Region eq ('North' AND Quantity lt 160)
 71         OR Customer eq "Pet's are Us" ; /* Double "" because Pet's*/
 ERROR: WHERE clause operator requires compatible variables.
 72         run ;

Thanks.


Accepted Solutions
Solution
‎04-18-2018 11:10 AM
Super User
Posts: 2,509

Re: Help with the Where clause proc print

[ Edited ]
Posted in reply to ManitobaMoose
('North' AND Quantity lt 160) 

is a test. It returns a boolean value (0 or 1).

 

Then you test region eq 1, which triggers the message as the values are of different type.

 

Your test is malformed. You probably mean

 

	where (Region eq 'North' AND Quantity lt 160) 
	   OR Customer eq "Pet's are Us" ; 

 

 

 

View solution in original post


All Replies
Solution
‎04-18-2018 11:10 AM
Super User
Posts: 2,509

Re: Help with the Where clause proc print

[ Edited ]
Posted in reply to ManitobaMoose
('North' AND Quantity lt 160) 

is a test. It returns a boolean value (0 or 1).

 

Then you test region eq 1, which triggers the message as the values are of different type.

 

Your test is malformed. You probably mean

 

	where (Region eq 'North' AND Quantity lt 160) 
	   OR Customer eq "Pet's are Us" ; 

 

 

 

Frequent Contributor
Posts: 130

Re: Help with the Where clause proc print

Great, Thanks.

 

What about if I write the code:

Libname Review'/folders/myfolders/Review' ;
Libname Learn'/folders/myfolders/Learn' ;  
Libname myformat'/folders/myfolders/sasuser.v94' ; 
Options fmtsearch=(myformat) ;

Proc Print data=learn.sales noobs ; 
	where (Region eq 'North' AND Quantity lt 160) ; 
	where Customer eq "Pet's are Us" ; /* Double "" because Pet's*/
run ; 

This seems to only produce results for the second where clause (Pets are Us). Why is that?
Super User
Posts: 2,509

Re: Help with the Where clause proc print

Posted in reply to ManitobaMoose

the second clause replaces the first one.

is this home work?

Frequent Contributor
Posts: 130

Re: Help with the Where clause proc print

Hi, I'm teaching myself SAS from Learning SAS by Example. It has answers to only the odd problems. Plus, it helps to learn the concept by going on here when I am truly unclear about something.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 102 views
  • 0 likes
  • 2 in conversation