BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Vergriffenego
Fluorite | Level 6

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

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;
Vergriffenego
Fluorite | Level 6

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:

Spoiler
649 do i = 1 to fim(totalcvd);
---
68
ERROR: Illegal reference to the array totalcvd.
ERROR 68-185: The function FIM is unknown, or cannot be accessed.

Is "fim" a typo? I also searched online, and did not find a similar word.

 

Thank you so much!

 

SASKiwi
PROC Star

do i = 1 to fim(totalcvd);

Yes, this should be the SAS function DIM.

Vergriffenego
Fluorite | Level 6
Thanks a lot Kiwi! It is DIM. And I was also trying to just put the numbers of icds. I got the same result. This is really amazing!
Vergriffenego
Fluorite | Level 6
Sure! Thanks a lot! It works very well!
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2209 views
  • 2 likes
  • 3 in conversation