BookmarkSubscribeRSS Feed
jcis7
Pyrite | Level 9

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;

3 REPLIES 3
Tom
Super User Tom
Super User

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;

ScottBass
Rhodochrosite | Level 12

Untested but should work:


data new;

   set old;

   if tot ge 10;

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

run;


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
Sudhakar_A
Calcite | Level 5

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1393 views
  • 0 likes
  • 4 in conversation