Hi all,
I need to pull the claims data with 20 procedure codes, and all the procedure codes are stored in a procedure code lookup table. Is there a simpler way to do that?
My code:
proc sql;
create table claims_data as
select distinct a.patient_id
,a.claim_num
,a.service_dt
,pr1.proc_1_cd
,pr2.proc_2_cd
,pr3.proc_3_cd
...
,pr20.proc_20_cd
from claim_file a
left join proc_lookup on pr1 on a.proc_1_cd_id=pr1.proc_cd_id
left join proc_lookup on pr2 on a.proc_2_cd_id=pr2.proc_cd_id
left join proc_lookup on pr3 on a.proc_3_cd_id=pr3.proc_cd_id
...
;quit;
In the procedure code lookup table, there are fields like this:
Field_num | Field_Name |
1 | PROC_CD_ID |
2 | PROC_CD_CD |
3 | PROC_CD_DESC |
4 | PROC_CD_TYPE |
PROC_CD_ID is the primary key.
Thank you all!
Lizi
Here is a quick example of the lookup table:
PROC_CD_ID | PROC_CD | PROC_CD_DESC | PROC_CD_TYPE |
7096 | 86376 | MICROSOMAL ANTIBODIES, EACH | C |
7098 | 86382 | NEUTRALIZATION TEST, VIRAL | C |
7099 | 86384 | NITROBLUE TETRAZOLIUM DYE TE | C |
7100 | 86403 | PARTICLE AGGLUTINATION; SCRE | C |
7102 | 86430 | RHEUMATOID FACTOR; QUALITATI | C |
The first field PROC_CD_ID is available in both the claim file and the lookup table while the second field PROC_CD is only available in the lookup table. I need to pull the field PROC_CD through joining PROC_CD_ID in both tables.
Thank you!
data have;
infile cards dlm=',';
informat ID $1. proc_1_cd proc_2_cd proc_3_cd proc_4_cd proc_5_cd $8.;
input ID $ proc_1_cd proc_2_cd proc_3_cd proc_4_cd proc_5_cd ;
cards;
A, 123.43, 124.34, 134.35, 124.89, 343.43
B, 423.43, 456.86, 129, 124.89, 145
C, 123.43, 124.34, 134.35, 124.89, 285.95
D, 854.70, 874.6, 68.55, 294.1, 4.5
E, 123.43, 124.34C, 134.35B, 124.89, 89.65A
;;;;
run;
proc sql;
create table distinct_codes as
select distinct proc_1_cd from have
union
select distinct proc_2_cd from have
union
select distinct proc_3_cd from have
union
select distinct proc_4_cd from have
union
select distinct proc_5_cd from have;
quit;
proc sql;
create table codes_not_found as
select * from lookup where proc_cd not in (select distinct proc_code from distinct_codes);
quit;
Either create a format from the proc_lookup table, or read it into a hash object and use arrays and a DO loop to do the lookup.
Example code:
data proc_lookup;
input proc_cd_id proc_cd_cd $;
datalines;
1 x
2 y
3 z
;
data have;
input proc_1_cd_id proc_2_cd_id;
datalines;
1 1
2 3
1 2
;
data want;
set have;
array proc_id {2} proc_1_cd_id proc_2_cd_id;
array codes {2} $ proc_1_cd_cd proc_2_cd_cd;
if _n_ = 1
then do;
length proc_cd_id 8 proc_cd_cd $8;
declare hash l (dataset:"proc_lookup");
l.definekey("proc_cd_id");
l.definedata("proc_cd_cd");
l.definedone();
end;
do i = 1 to 2;
proc_cd_id = proc_id{i};
if l.find() = 0 then codes{i} = proc_cd_cd;
end;
drop i;
run;
What database is that? A simpler approach would be for your DBA to create a view combining the 20 lookup tables, then you do one join to the view.
You are working with SAS, so the data step is available.
If, OTOH, this is to be done directly on the DB via explicit passthrough, consult the DBA's, or a community for that particular DB environment.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: