sas - difference between call missing of an array and setting every element of array to zero -


consider

data want; set have; array ay1{7}; retain ay1:;  if first.tcol do; call missing(of ay1{*}); end;  if ay1{7} > do; [other statements determine value of ay1] end;  else do; [other statements determine value of ay1] end;  tcol; run; 

since array ay1 automatically retained between observations, if want program by-group processing, need reset ay1 values when encounter new tcol value (otherwise inherit values last observation of previous tcol value. affect if ay{7} > a, hence other statements followed affected).

in current codes, reset array by

do = 1 dim(ay1); ay1{i} = 0; end; 

and work fines. first obs of each tcol value, first reset values of ay1 0 , perform [other statement] update ay1 in observation.

if use call missing(of ay1{*});, first obs of each tcol value, set each value of ay1 missing (as expected). following [other statement] not update ay1. (i have placed several put statements in [other statement] debug step make sure part has run. other work except updating ay1 value).

if first.tcol fails, seems normal (no error output data set wrong since first step in each group has unexpected values). think there must wrong using call missing here.

your statement "since array ay1 automatically retained between observations" incorrect. arrays declared _temporary_ retained automatically. arrays of permanent variables not.

you can test with:

data want; set have; array ay1{7}; tcol;  if first.tcol do;     i=1 7;         ay1[i] = 1;     end; end; run; 

you see after first tcol value in each group, values missing. i.e. not retained between rows.

add

retain ay:; 

to data step , should work expect.

edit: added show works described.

data have; tcol = 1; = 1; output; tcol = 1; = 10; output; run;  data want; set have; array ay1{7}; retain ay1:; tcol;  if first.tcol do;     call missing(of ay1{*}); end;  if ay1{7} > do;     i=1 7;         ay1[i] = -a;     end; end;  else do;     i=1 7;         ay1[i] = 999;     end; end;  run; 

Comments