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

Hello,

 

I am pulling data from a database using PROC SQL and there is a WHERE condition I am unsure on how to input. The pull is one table with several columns (variables) and I want to exclude rows when two of the columns have a specific value each.

 

As an example, call the columns Alpha and Beta. If in one row, Alpha has the value C and in that same row, Beta has the value X, I do not want that row in the pull. But if Alpha has the value C and Beta has any other value but X, or if Beta has the value X and Alpha has any other value but C, I do want those rows. Any help on this is appreciated, thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @Sas_Act_114 

 

Try this in the inner select: where NOT (Alpha = "C" and Beta = "X")

View solution in original post

5 REPLIES 5
ballardw
Super User

Some concrete example of the sources and then the desired result.

In general SQL does not have a concept of "row order". There would have to be some other criteria provided to join the data on, or are you doing a full Cartesian Join of all rows from each table?

Sas_Act_114
Fluorite | Level 6

I apologize if I wasn't clear enough in the original post. There is no joins, I am simply pulling the data from one table, which even that I do not believe to be relevant. For all intensive purposes, this just involves one table (or dataset if you will) with several variables/columns in the one table. As an example of the table (with just 3 columns):

 

ID  Alpha  Beta

1       C        X

2       P        X

3       C        T

4       P        T

5       C       X

 

When I pull this table, I want it to keep rows 2, 3 and 4, excluding 1 and 5 due to the Alpha having C and Beta having X. The pull is very simple, it is simply (code edited with general table name and source):

 

PROC SQL;
CONNECT TO ODBC;
CREATE TABLE TEST1 AS
SELECT *
FROM CONNECTION TO ODBC
(
SELECT *
FROM SOURCE.TABLE 

);DISCONNECT FROM ODBC;

I am looking for a where statement that will not include rows 1 and 5, as shown in the example above.

ErikLund_Jensen
Rhodochrosite | Level 12

Hi @Sas_Act_114 

 

Try this in the inner select: where NOT (Alpha = "C" and Beta = "X")

Sas_Act_114
Fluorite | Level 6
This was the command I needed, worked perfectly, thank you.
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
  • 5 replies
  • 4497 views
  • 2 likes
  • 4 in conversation