BookmarkSubscribeRSS Feed
Miracle
Barite | Level 11

Hi SAS users,

 

I would like to join 2 tables on 2 variables limiting only the records from condition_concept table.

But the below code doesn't work.

Would you be able to point me out why?

Thank you.

 

CREATE TABLE criteria AS
	SELECT a.*, a.year AS condition_year, b.year AS visit_year 
	FROM condition a INNER JOIN visit b
	ON a.id=b.id AND a.visit_id=b.visit_id
	WHERE condition_id IN 
	(SELECT DISTINCT(target_id) FROM condition_concept)
	ORDER BY a.id
3 REPLIES 3
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

does your condition have a table that it is coming from is it table a or table b?

Astounding
PROC Star

If this were a DATA step instead of SQL, the answer would be very clear.  Since it's SQL, however, you will have to check whether this is correct or not.

 

A stand-alone WHERE clause applies to both sources of data.  Both CONDITION and VISIT would need to contain CONDITION_ID.

 

If it turns out that SQL follows the same rules, (and if CONDITION_ID appears in only one of the incoming data sets), you could get around the issue by using two CREATE statements.

 

CREATE statement #1:  Create a view that subsets the records from one of the sources.

 

CREATE statement #2:  Join that view with the other source.

 

Of course, if this is not the issue, it would be helpful for you to provide some details ... what doesn't work?  Why is the result not what you want?  The SAS log would help.

ballardw
Super User

Doesn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

 

And you are using three tables. Perhaps you need to JOIN with the third table instead?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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