DATA Step, Macro, Functions and more

Array subscript out of range

Reply
Regular Contributor
Posts: 194

Array subscript out of range

I'm trying to fill fields per row as missing (currently some fields have zeros) for certain rows, where rep='N'.

All variables I'm replacing as missing either have a numerical value of zero or are missing.

But I'm getting an error:  Array subscript out of range at line 409 column 28.

data new;


set old;


if tot ge 10;


array vars var1 var2 var3 var4 var5 var6 var7;




if rep = 'N' then vars=.;


run;

Super User
Super User
Posts: 7,060

Re: Array subscript out of range

I am assuming that you want to assign missing to each of the variables when REP='N'.

if rep='N' then do over vars; vars=.; end;

or if you do not like the old style DO OVER then use an explicit index variable.

if rep='N' then do _n_=1 to dim(vars); vars(_n_)=. ; end;

Super Contributor
Posts: 387

Re: Array subscript out of range

Untested but should work:


data new;

   set old;

   if tot ge 10;

   if rep = 'N'  then call missing(of varSmiley Happy;  /* or call missing(of var1-var7);  read the doc on "of" keyword and variable lists */

run;

Contributor
Posts: 60

Re: Array subscript out of range

if rep = 'N' then call missing(of var1-var7);

Ask a Question
Discussion stats
  • 3 replies
  • 593 views
  • 0 likes
  • 4 in conversation