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

Hello Community - 

 

I have an extremely simple coding question, which I am stuck at:

My current code is (which resulted in an abort to the teradata due to size limitation):

 

PROC SQL;
CREATE TABLE Short_Table AS
SELECT DISTINCT *

From All_Data

where variable1 = 123

and variable2 = 'xyz' or variable3 = 'abc' /*cause of the error, because it pulls all the data*/

Quit;

 

I also tried this version:

and (variable2 = 'xyz' or variable3 = 'abc') /* the results did not include the variable3 condition*/

 

Thank you in  advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

First:

where variable1 = 123 and variable2 = 'xyz' or variable3 = 'abc' 

is equivalent to

where (variable1 = 123 and variable2 = 'xyz') or variable3 = 'abc' 

as "and" is evaluated before "or".

So your try

where variable1 = 123 and (variable2 = 'xyz' or variable3 = 'abc') 

is correct, but depends on the actual contents of variable3. Spelling, uppercase/lowercase, leading blanks can all cause your condition to never be true.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

You have told us what doesn't work, but we don't know what output you do want.

 

Can you show us a small data set as an example, with the desired output?

--
Paige Miller
Kurt_Bremser
Super User

First:

where variable1 = 123 and variable2 = 'xyz' or variable3 = 'abc' 

is equivalent to

where (variable1 = 123 and variable2 = 'xyz') or variable3 = 'abc' 

as "and" is evaluated before "or".

So your try

where variable1 = 123 and (variable2 = 'xyz' or variable3 = 'abc') 

is correct, but depends on the actual contents of variable3. Spelling, uppercase/lowercase, leading blanks can all cause your condition to never be true.

ballardw
Super User

Since you say you had an error that "pulls all the data" then you might want to share some of the value incorrectly pulled and explain why those are incorrect. The values would only have to be from your variables 1 , 2 and 3.

 

However these may need to be actual values and not your moderately obvious dummy values.

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 697 views
  • 1 like
  • 4 in conversation