Hi team,
i have the following code and the log
could you help me where i am going wrong in the code???
Thanks
1310 data dummy;
1311 set dummy;
1312 array diag(35) dx1-dx35;
1313 do i= 1 to 35;
1314 if put(diag{i},$cancer.)=1 then do cancer=1;
1315 end;
1316 if cancer=. then cancer=0;
1317 if put(diag{i},$Diabetes.)=1 then do Diabetes=1;
1318 end;
1319 if Diabetes=. then Diabetes=0;
1320 end;
1321 if put(diag{i},$CAD.)=1 then do CAD=1;
1322 end;
1323 if CAD=. then CAD=0;
1324 if put(diag{i},$CHF.)=1 then do CHF=1;
1325 end;
1326 if CHF=. then CHF=0;
1327 drop i;
1328 run;
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
1314:12 1317:12 1321:12 1324:12
ERROR: Array subscript out of range at line 1321 column 16.
Sorry, you're right. It's just the extra "end" on line 1320. That has to be moved to later in the DATA step to avoid ending the loop (starting on 1313) prematurely.
put function creates character variable.
put(diag{i},$cancer.)=1
should be
put(diag{i},$cancer.)="1"
hi Linlin,
thanks for the quick response.
Even after i changed it to have quotes the same error message appears
Thanks
There might be a few ways to simplify your code. But the quick answer to get rid of the error is to look at line 1319. It's missing the word "do". Every other time, you have said the equivalent of "do Diabetes=0". But here the word "do" is omitted, which leads to a series of events:
(1) Line 1320 ends the DO loop that begins on line 1313.
(2) On Line 1321, i is 36, which is out of range for the array of 35 elements.
If you add "do" on line 1319, you will need to add the "end" to match with line 1313.
Better style would reorder the logic (abbreviated here):
cancer=0;
diabetes=0;
do i=1 to 35;
if put(dx{i}, $CANCER.)="1" then cancer=1;
if put(dx{i}, $DIABETES.)="1" then diabetes=1;
end;
Good luck.
Hi Astounding,
equivalent of "do Diabetes=0".??????????
I checked again and i dint use do on others!!!!!!!!!!!
Could you verify one more time please?
Thanks
Sorry, you're right. It's just the extra "end" on line 1320. That has to be moved to later in the DATA step to avoid ending the loop (starting on 1313) prematurely.
Hi,
Thanks so much. I removed the "END" on line 1320 and placed an additional "end" just prior to the "drop i statement
Is that the right approach?????
thanks
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.