Array Out of Bound Error

  • Follow


Hi All,

I am getting the below error:

ERROR: Array subsCCipt out of range at line 281 column 18


Below is my code:



data rs1;
   set rs_t;

   *24 cells in array;
   array rbv $ col222 col422 col522 col622 col722 col822 col922 col1022
col1122 col1222 col1322 col1422 col1522 col1622 col1722 col1822 col1922
col2022 col2122 col2222 col2322 col2422 col777 col997;

   length sts $10;

       do i = 1 to 23;


         if rbv{i} = 'CC' then sts = 'CC';
         if rbv{i} = 'PP' and sts not in ('CC','DD') then sts = 'PP';
         if rbv{i} = 'SS' and sts not in ('CC','PP','DD') then sts = 'SS';
         if rbv{i} = 'DD' and sts not in ('CC','PP','SS') then sts = 'DD';



         *if rbv{i} = 'PP' and rbv{i+1} = 'PP' then cfm_PP_flg = 1;
         *if rbv{i} = 'CC' and rbv{i+1} = 'CC' then cfm_CC_flg = 1;


         if rbv{i} eq 'PP' then do;
         if rbv{i+1} eq 'PP' then do;
            cfm_PP_flg = 1;
         end;
         else if rbv{i+2} eq 'PP' then do;
            cfm_PP_flg = 1;
         end;
         end;


         if rbv{i} eq 'CC' then do;
         if rbv{i+1} eq 'CC' then do;
            cfm_CC_flg = 1;
         end;
         else if rbv{i+2} eq 'CC' then do;
            cfm_CC_flg = 1;
         end;
         end;

     end;
run;
0
Reply sjain (15) 12/3/2009 6:17:26 PM

You have the following condition in your code:

else if rbv{i+2} eq 'CC' then do;

Since you only have a 24 element array, and are looping from 1 to 23, that
will produce the error if i=23.

HTH,
Art
----------
On Thu, 3 Dec 2009 13:17:26 -0500, Siddharth Jain <sjain@AVEOPHARMA.COM>
wrote:

>Hi All,
>
>I am getting the below error:
>
>ERROR: Array subsCCipt out of range at line 281 column 18
>
>
>Below is my code:
>
>
>
>data rs1;
>   set rs_t;
>
>   *24 cells in array;
>   array rbv $ col222 col422 col522 col622 col722 col822 col922 col1022
>col1122 col1222 col1322 col1422 col1522 col1622 col1722 col1822 col1922
>col2022 col2122 col2222 col2322 col2422 col777 col997;
>
>   length sts $10;
>
>       do i = 1 to 23;
>
>
>         if rbv{i} = 'CC' then sts = 'CC';
>         if rbv{i} = 'PP' and sts not in ('CC','DD') then sts = 'PP';
>         if rbv{i} = 'SS' and sts not in ('CC','PP','DD') then sts = 'SS';
>         if rbv{i} = 'DD' and sts not in ('CC','PP','SS') then sts = 'DD';
>
>
>
>         *if rbv{i} = 'PP' and rbv{i+1} = 'PP' then cfm_PP_flg = 1;
>         *if rbv{i} = 'CC' and rbv{i+1} = 'CC' then cfm_CC_flg = 1;
>
>
>         if rbv{i} eq 'PP' then do;
>         if rbv{i+1} eq 'PP' then do;
>            cfm_PP_flg = 1;
>         end;
>         else if rbv{i+2} eq 'PP' then do;
>            cfm_PP_flg = 1;
>         end;
>         end;
>
>
>         if rbv{i} eq 'CC' then do;
>         if rbv{i+1} eq 'CC' then do;
>            cfm_CC_flg = 1;
>         end;
>         else if rbv{i+2} eq 'CC' then do;
>            cfm_CC_flg = 1;
>         end;
>         end;
>
>     end;
>run;
0
Reply art297 (4237) 12/3/2009 7:01:23 PM


always let SAS count the number of vars in an array:

>        do i = 1 to 23;

>        do i = 1 to dim(rbv);

>          if rbv{i+1} eq 'PP' then do;
>             cfm_PP_flg = 1;
>          end;
>          else if rbv{i+2} eq 'PP' then do;
>             cfm_PP_flg = 1;
>          end;

as Art has pointed out
you are referring to two elements beyond
the upper bound of your array;
contrain your code:

if I le dim(rbv) -2 then do;
>          if rbv{i+1} eq 'PP' then do;
>             cfm_PP_flg = 1;
>          end;
>          else if rbv{i+2} eq 'PP' then do;
>             cfm_PP_flg = 1;
>          end;
end;

Ron Fehd  the macro maven  CDC Atlanta GA USA RJF2 at cdc dot gov


> -----Original Message-----
> From: owner-sas-l@listserv.uga.edu
> [mailto:owner-sas-l@listserv.uga.edu] On Behalf Of Siddharth Jain
> Sent: Thursday, December 03, 2009 1:17 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Array Out of Bound Error
>
> Hi All,
>
> I am getting the below error:
>
> ERROR: Array subsCCipt out of range at line 281 column 18
>
>
> Below is my code:
>
>
>
> data rs1;
>    set rs_t;
>
>    *24 cells in array;
>    array rbv $ col222 col422 col522 col622 col722 col822
> col922 col1022
> col1122 col1222 col1322 col1422 col1522 col1622 col1722
> col1822 col1922
> col2022 col2122 col2222 col2322 col2422 col777 col997;
>
>    length sts $10;
>
>        do i = 1 to 23;
>
>
>          if rbv{i} = 'CC' then sts = 'CC';
>          if rbv{i} = 'PP' and sts not in ('CC','DD') then sts = 'PP';
>          if rbv{i} = 'SS' and sts not in ('CC','PP','DD')
> then sts = 'SS';
>          if rbv{i} = 'DD' and sts not in ('CC','PP','SS')
> then sts = 'DD';
>
>
>
>          *if rbv{i} = 'PP' and rbv{i+1} = 'PP' then cfm_PP_flg = 1;
>          *if rbv{i} = 'CC' and rbv{i+1} = 'CC' then cfm_CC_flg = 1;
>
>
>          if rbv{i} eq 'PP' then do;
>          if rbv{i+1} eq 'PP' then do;
>             cfm_PP_flg = 1;
>          end;
>          else if rbv{i+2} eq 'PP' then do;
>             cfm_PP_flg = 1;
>          end;
>          end;
>
>
>          if rbv{i} eq 'CC' then do;
>          if rbv{i+1} eq 'CC' then do;
>             cfm_CC_flg = 1;
>          end;
>          else if rbv{i+2} eq 'CC' then do;
>             cfm_CC_flg = 1;
>          end;
>          end;
>
>      end;
> run;
>
>
0
Reply rjf2 (3354) 12/3/2009 9:51:51 PM

2 Replies
156 Views

(page loaded in 0.172 seconds)

Similiar Articles:













7/27/2012 11:52:57 PM


Reply: