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!
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.
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?
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.
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.
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.
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.