BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Panagiotis
SAS Employee

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: 

 

 

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

I guess you meant

 

data BREAST_ED_REASONS_GS_092718;
MERGE raw.BREAST_DIAG_PRTY1 raw.ICD10_CLASSIFICATIONS;
BY DIAG_CD;
RUN;
PG
Panagiotis
SAS Employee

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: 

 

 

VenuKadari
SAS Employee

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 947 views
  • 2 likes
  • 4 in conversation