How do I see if records with matching keys are in both files and then output only the records that are in the second file into a new file?
proc sql;
create table cohort2 as
select *
from etl.inp_claims_lds2013_2014_lejr etl.inp_claims_lds2015_2016_lejr
where etl.inp_claims_lds2015_2016_lejr.desy_sort_key in (select
desy_sort_key from etl.inp_claims_lds2013_2014_lejr);
quit;
What do you think is wrong with your code. Seems ok or am i not understanding your description?
my tired eyes didn't capture the missing comma in from clause
from etl.inp_claims_lds2013_2014_lejr , etl.inp_claims_lds2015_2016_lejr
check that.
also, at late evening here don't trust my eyes
what's your objective
Are you after this logic?
proc sql;
select *
from b
where key in (select key from a);
quit;
You are better off posting a sample of your data and the requirement
SAS/SQL doesn't support 3-level variable names. You must use aliasses :
from etl.inp_claims_lds2013_2014_lejr as a, etl.inp_claims_lds2015_2016_lejr as b
where b.desy_sort_key in (select
desy_sort_key from etl.inp_claims_lds2013_2014_lejr)
thanks - below it states it cannot find my files but they are in library ETL. Is there something else i need to add
73 libname etl 'D:\Medicare\05_etl_output\';
NOTE: Libref ETL was successfully assigned as follows:
Engine: V9
Physical Name: D:\Medicare\05_etl_output
74
75 proc sql;
76 create table cohort as
77 select *
78 from etl.inp_claims_2013_2014_lejr as a, etl.inp_claims_2015_2016_lejr as b
79 where b.desy_sort_key in (select
80 desy_sort_key from a);
ERROR: File ETL.INP_CLAIMS_2013_2014_LEJR.DATA does not exist.
ERROR: File ETL.INP_CLAIMS_2015_2016_LEJR.DATA does not exist.
ERROR: File WORK.A.DATA does not exist.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
81 quit;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.