Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

how do I merge two tables with same columns if I just want data that is in both tables based on cert

Reply
Contributor
Posts: 24

how do I merge two tables with same columns if I just want data that is in both tables based on cert

how do I merge two tables with same columns if I just want data that is in both tables based on certain columns? I tried using this but it doesnt seem to work.

 

PROC SQL;

CREATE Table parta as

Select *

from step2

where SERVCODN IN ('96372');

quit;

 

PROC SQL;

CREATE Table partb as

Select *

from step2

where SERVCODN NOT IN ('96372');

 

PROC SQL;

Create table results as

SELECT parta.*,partb.*

FROM parta, partb

WHERE parta.memno = partb.memno

and parta.claimno = partb.claimno

and parta.APPL_FULL_SVC_NBR = partb.APPL_FULL_SVC_NBR;

quit;

Contributor
Posts: 44

Re: how do I merge two tables with same columns if I just want data that is in both tables based on

I ran your code and it's working i.e giving rows that have common values between datasets. I strongly recommnend you to check your data to see if you have a match. Also let me know if you are expecting something else. Good Luck.

 

data step2 ;
input SERVCODN $ memno claimno APPL_FULL_SVC_NBR;
datalines ;
96372 10 96 100
96372 27 50 102
96520 27 50 102
90222 10 96 100
90001 22 85 104
;
run ;

PROC SQL;
CREATE Table parta as
Select *
from step2
where SERVCODN IN ('96372');
quit;

PROC SQL;
CREATE Table partb as
Select *
from step2
where SERVCODN NOT IN ('96372');

proc print data=parta;run ;
proc print data=partb;run ;

PROC SQL;

SELECT parta.*,partb.*
FROM parta, partb
WHERE parta.memno = partb.memno
and parta.claimno = partb.claimno
and parta.APPL_FULL_SVC_NBR = partb.APPL_FULL_SVC_NBR;
quit;

Super User
Posts: 10,538

Re: how do I merge two tables with same columns if I just want data that is in both tables based on

Please describe in a bit of detail how it "doesn't work". We do not have your data so cannot duplicate your results. It appears that the code could work but: If you get error messages then post the log with the error messages. It is best to post the log information in an entry box opened with the "run" icon as some of the info in the error message relies on position that the main forum entry will remove.

 

If the result is unexpected or no output then provide examples of all input data and the desired output. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will help you post SAS data set(s) as data step code to allow us to recreate your actual data. If you post text or picture we have to write code and guess as to your variable types and may get something that works for that but not your data.

 

Your code could fail because 1) there are no records with SERCOCDN = '96372' or 2) none of the records that do not have SERVCODN = '96372' have a match on all three of Memno, Claimno and APPL_FULL_SVC_NBR.

If you wanted to see if any of the three match then you want to use OR instead of AND in the where clause.

Ask a Question
Discussion stats
  • 2 replies
  • 207 views
  • 0 likes
  • 3 in conversation