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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 421 views
  • 1 like
  • 4 in conversation