Using SAS 9.4
I am trying to merge 2 datasets based on diagnosis code. I have 1 table with many diagnosis codes repeated and then another table that has the individual diagnosis codes.
I ran this code:
data BREAST_ED_REASONS_GS_092718;
MERGE raw.BREAST_DIAG_PRTY1 raw.ICD10_CLASSIFICATIONS;
WHERE BREAST_DIAG_PRTY1.DIAG_CD=ICD10_CLASSIFICATIONS.DIAG_CD;
RUN;
When I run this code I have 344 unique codes that merge over to the original dataset, however I need it to match to 1500 codes. Any help would be appreciated! Thank you
Just by looking at your code, I am assuming you have some experience in SQL? It looks like you are trying to use the WHERE statement like you would in SQL.
In SAS the MERGE statement needs the BY Statement. The by statement will tell SAS what columns to merge on. The column that you are merging on must have the same name in both tables (which yours looks like it does) and be sorted in both tables.
Without really understanding the data and your goal,I can only get you started. Your code should look something like this:
data BREAST_ED_REASONS_GS_092718;
MERGE raw.BREAST_DIAG_PRTY1 raw.ICD10_CLASSIFICATIONS;
BY DIAG_CD;
RUN;
But here is some documentation for you to look at:
I guess you meant
data BREAST_ED_REASONS_GS_092718;
MERGE raw.BREAST_DIAG_PRTY1 raw.ICD10_CLASSIFICATIONS;
BY DIAG_CD;
RUN;
Just by looking at your code, I am assuming you have some experience in SQL? It looks like you are trying to use the WHERE statement like you would in SQL.
In SAS the MERGE statement needs the BY Statement. The by statement will tell SAS what columns to merge on. The column that you are merging on must have the same name in both tables (which yours looks like it does) and be sorted in both tables.
Without really understanding the data and your goal,I can only get you started. Your code should look something like this:
data BREAST_ED_REASONS_GS_092718;
MERGE raw.BREAST_DIAG_PRTY1 raw.ICD10_CLASSIFICATIONS;
BY DIAG_CD;
RUN;
But here is some documentation for you to look at:
data work.BREAST_DIAG_PRTY1;
DIAG_CD=111;
Field_One='A_111';
output;
DIAG_CD=111;
Field_One='B_111';
output;
DIAG_CD=111;
Field_One='C_111';
output;
DIAG_CD=222;
Field_One='A_222';
output;
DIAG_CD=222;
Field_One='B_222';
output;
run;
data work.ICD10_CLASSIFICATIONS;
DIAG_CD=111;
Field_Two='X_111';
output;
DIAG_CD=222;
Field_Two='Y_222';
output;
run;
proc sort data = work.BREAST_DIAG_PRTY1; By DIAG_CD; run;
proc sort data = work.BREAST_DIAG_PRTY1; By DIAG_CD; run;
data work.BREAST_ED_REASONS_GS_092718;
MERGE work.BREAST_DIAG_PRTY1 work.ICD10_CLASSIFICATIONS;
by DIAG_CD;
RUN;
proc print; run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.