Hi,
there are 25 variables all with icd code in a sas files a, I need to create another 25 variables come with phecode based on ICD code and phecode library b.
file a looks like:
Id dx1 dx2....dx25;
file b just have two variables:
icd phecode
I want a dataset like:
id dx1 dx2 ....dx25 phecode1 phecode2 ....phecode25;
I tried below code:
%macro create_phecode_vars;
%do i = 1 %to 25;
proc sql;
create table dxn as
select a.*, b.phecoden as phecode&i
from dxn a left join phecn b
on a.dx&i eq b.icdn
;
quit;
%end;
%mend;
Log show WARNING: This CREATE TABLE statement recursively references the target table. A consequence of
this is a possible data integrity problem.
Any suggestions are appreciated.
Use a format instead.
https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/001-30.pdf
data icd_fmt;
set phecn;
fmtname='dxfmt';
type='C';
start=icd;
label = phecode;
run;
proc format cntlin=icd_fmt;
run;
data want;
set have;
array _dx(*) dx1-dx25;
array _phe(*) $10. phecode1-phecode25;
do i=1 to dim(_dx);
if not missing(_dx(i)) then phecode(i) = put(_dx(i), dxfmt.);
end;
run;
Hi Reeza,
it shows.
my icd-phecode library have some repeat code.
Thank you.
Yes, I have much more ICD code than Phecode, it is not 1-to -1. I just want to do if dx(i) match icd, then phe(i)=phecode. but my database is big and with repeat.
Would it possible to keep all the matched phecode? The file has 155,881 match lines with just 97,852 unique icd code. Thank you.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.