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;
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;
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;
if rep = 'N' then call missing(of var1-var7);
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.
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.