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);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.