BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
bhca60
Quartz | Level 8
proc sql;
create table Btable
as select
    id,
    name,
    dob
FROM table1
UNION
SELECT 
    id,
	name,
	dob
FROM table2
where id IN ('12345' '123456');
quit;

I have tried everything to filter on these two ID's but i keep getting errors. I tried separating with a comma, semicolon - nothing seems to work.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Is ID a numeric variable or a character variable?  Does it have a format attached to it? Which format? Is it a SAS system format or a user defined format.  Remember you need to test for the actual values, not the values are displayed by the format.

 

Why are you filtering on just one of the two tables you are combining?

View solution in original post

6 REPLIES 6
SASKiwi
PROC Star

There is no obvious syntax error in your posted code. You need to post your complete SAS log including notes and errors so we can see what is happening.

ballardw
Super User

AS an absolute minimum include the actual text of any errors. Much better is to show the entire log for the procedure run with the code and all notes, warnings or errors associated with that procedure. Copy the text from the LOG, on the forum open a text box using the </> icon above the message window and paste the copied text.

 

Is it as simple as your ID variable is numeric and you are getting errors about the wrong type such as

ERROR: Expression using IN has components that are of different data types.

Then don't put quotes around the values.

bhca60
Quartz | Level 8
I've gotten that error before but I got this error for the above:
ERROR: Expression using IN has components that are of different data types.
NOTE: The IN referred to may have been transformed from an OR to an IN at some point during PROC SQL WHERE clause optimization.

Nothing seems to work - single quotes, double quotes, commas, no commas, semicolons...sometimes it just ignores the filter entirely and brings in all data. when i remove the quotes, it brings in all data.
Tom
Super User Tom
Super User

Is ID a numeric variable or a character variable?  Does it have a format attached to it? Which format? Is it a SAS system format or a user defined format.  Remember you need to test for the actual values, not the values are displayed by the format.

 

Why are you filtering on just one of the two tables you are combining?

bhca60
Quartz | Level 8
that was it! i didnt filter on both - thank you thank you!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 6 replies
  • 1951 views
  • 0 likes
  • 5 in conversation