BookmarkSubscribeRSS Feed
wj2
Quartz | Level 8 wj2
Quartz | Level 8

Hello Community, 

 

I am receiving the error message below regarding an array that I am trying to run. I have also provided my code below that. Specifically, I am trying to create a variable (newvar) indicating whether any diagnosis from a set of diagnoses (&painlist) is within 12 months of any diagnosis from a different set (F12.10, F12.20, ...). Can someone please assist me with resolving this issue? Any feedback would be much appreciated! 

 

ERROR: Array subscript out of range at line 196 column 3.
i=100 last.patient_identifier=0 patient_identifier=10 encounter_identifier=224529039 icd=H90.3
diagnosis_date=20JAN2016 diagnosis_type_description=FINAL DIAGNOSIS FIRST.patient_identifier=0
new_var=. m=. n=. dif_day=. yes=. _ERROR_=1 _N_=1

 

proc sort data=have;
by patient_identifier diagnosis_date;
run;


190 data want; 191 array _c{99} $ 32 _temporary_; 192 array _n{99} _temporary_; 193 do i=1 by 1 until(last.patient_identifier); 194 set have; 195 by patient_identifier; 196 _c{i}=icd; 197 _n{i}=diagnosis_date; 198 end; 199 new_var=0; 200 do m=1 to i-1; 201 do n=m+1 to i; 202 if _c{n} in 202! ('F12.10','F12.120','F12.121','F12.122','F12.129','F12.150','F12.151','F12.159','F12.180','F12.18 202! 8', 203 'F12.19','F12.20','F12.221','F12.222','F12.229','F12.23','F12.250','F12.251','F12.259','F12.288', 203! 'F12.29','F12.90', 204 'F12.920','F12.921','F12.922','F12.929','F12.93','F12.950','F12.951','F12.959','F12.980','F12.988 204! ','F12.99','304.3', 205 '304.30','304.31','304.32','305.2','305.20','305.21','305.22') 206 and _c{m} in (&painlist) 207 then do; 208 dif_day=_n{n}-_n{m}; 209 if dif_day le 365 or dif_day ge 365 then do;new_var=1;yes=1;leave;end; 210 end; 211 if yes then leave; 212 end; 213 end; 214 keep patient_identifier new_var; 215 run;
3 REPLIES 3
mkeintz
PROC Star

Patient identifier 10 apparently has more than 99 observations in dataset HAVE.

 

From the ERROR message in the log, you can observe:

 

  1. the error occurred in line 196, where you have _c{I}=idc;
  2. the list of variable values reports I=100
  3. the list of variable values reports patient_id=10.
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
wj2
Quartz | Level 8 wj2
Quartz | Level 8

@mkeintz Ah yes, thank you. Would you be able to suggest how the code might be modified to account for variable numbers of observations for each patient (e.g., patients with >99 observations)? 

ballardw
Super User

@wj2 wrote:

@mkeintz Ah yes, thank you. Would you be able to suggest how the code might be modified to account for variable numbers of observations for each patient (e.g., patients with >99 observations)? 


It may help to describe what you are actually attempting. Possibly a small example data set and the desired output.

You may also want to tell us how the resulting data set is to be used.

 

You might also tell us if you have access to SAS/IML as the way your are using the nested loops smells sort of like an attempt at matrix use.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 580 views
  • 0 likes
  • 3 in conversation