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
does your condition have a table that it is coming from is it table a or table b?
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.
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?
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.
Ready to level-up your skills? Choose your own adventure.