Hello,
I am working on CVD outcome based on ICD10. The database I have consists of patients with all kinds of diseases. Therefore, I need to find out who has CVD in the database. I was thinking to use "DO" loop. My idea is that if the OBS contains the ICD10 code for CVD then I will keep this OBS.
For example, this is 5 OBS of the database. (ID: patient id; icd1-icd5 were the diseases reported by the patients. Patients could have more than one disease.)
data cvd; input id icd1$ icd2$ icd3$ icd4$ icd5$; datalines; 1 K509 K523 K529 M241 . 2 A101 I210 K509 M050 I212 3 B310 K523 I051 . . 4 H100 H200 I607 I639 I501 5 I210 I211 I212 I213 . RUN; DATA CVDTRY; SET cvd; ARRAY TOTALCVD icd1 icd2 icd3 icd4 icd5; DO i = 'I210', 'I211', 'I212', 'I213', 'I214', 'I219', 'I051', 'I607'; IF TOTALCVD[i] = [i] THEN OUTPUT; END;
The log I got was:
ERROR: Undeclared array referenced: NAME. ERROR: Variable NAME has not been declared as an array. ERROR 22-322: Syntax error, expecting one of the following: a name, INPUT, PUT.
I was not sure it is appropriate to use this method, or are there any other approaches to solve problems like this?
Thank you!
The index into an array has to be an integer, not a character string:
data cvdtry;
set cvd;
array totalcvd {*} icd1-icd5;
do i = 1 to fim(totalcvd);
if totalcvd{i} in ('I210','I211','I212','I213','I214','I219','I051','I607')
then do;
icd = totalcvd{i};
output;
end;
end;
keep id icd;
run;
Or you transpose to long:
proc transpose
data=cvd
out=cvdtry (
drop=_name_
rename=(col1=icd)
where=(icd in ('I210','I211','I212','I213','I214','I219','I051','I607'))
)
;
by id;
var icd:;
run;
The index into an array has to be an integer, not a character string:
data cvdtry;
set cvd;
array totalcvd {*} icd1-icd5;
do i = 1 to fim(totalcvd);
if totalcvd{i} in ('I210','I211','I212','I213','I214','I219','I051','I607')
then do;
icd = totalcvd{i};
output;
end;
end;
keep id icd;
run;
Or you transpose to long:
proc transpose
data=cvd
out=cvdtry (
drop=_name_
rename=(col1=icd)
where=(icd in ('I210','I211','I212','I213','I214','I219','I051','I607'))
)
;
by id;
var icd:;
run;
Dear Mr. Bremser,
Thank you for the solution! The second one works well.
For the first solution, there seemed some problems with it.
After I ran it, the log reported me with:
Is "fim" a typo? I also searched online, and did not find a similar word.
Thank you so much!
do i = 1 to fim(totalcvd);
Yes, this should be the SAS function DIM.
That's a "tablet typo". "f" is right next to "d".
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.