/*数组运算*/
data ex1(drop=i j);
set ex;
count=0;
array aa(*) abc01ef abc02ef abc03ef;
do i=1 to dim(aa);
if missing(aa(i)) then j=0;
else j=1 ;
count+j;
end;
if count=0 then put "true";
else put "false";
run;
/*用宏做个循环没多大意思,用n函数更方便直接*/
data ex1;
set ex;
if n(abc01ef,abc02ef,abc03ef)=0 then put "true";
else put "false";
run;
Using the sum function can bypass an looping of array index. It is not only simpler, but also it runs faster as well. See the comparison at bottom.
There is no macro necessary in this context.
data t1;
array abc[*] abc01ef abc02ef abc03ef abc04ef;
do i=1 to 5;
do j=1 to dim(abc);
if i in (1,4,5) then abc[j]=ranuni(123);
else abc[j]=.;
end;
output;
end;
keep abc:;
run;
data t2;
set t1;
array abc[*] abc01ef abc02ef abc03ef abc04ef;
missflag=(sum(of abc[*])=.);
run;
proc print;run;
******************************
251 data t1;
252 array abc[*] abc01ef abc02ef abc03ef abc04ef;
253 do k=1 to 1e6;
254 do i=1 to 5;
255
256 do j=1 to dim(abc);
257 if i in (1,4,5) then abc[j]=ranuni(123);
258 else abc[j]=.;
259 end;
260 output;
261 end;
262 end;
263 keep abc:;
264 run;
NOTE: The data set WORK.T1 has 5000000 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 1.64 seconds
cpu time 1.57 seconds
265
266 data t2;
267 set t1;
268 array abc[*] abc01ef abc02ef abc03ef abc04ef;
269 missflag=(sum(of abc[*])=.);
270 run;
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
2000000 at 269:13
NOTE: There were 5000000 observations read from the data set WORK.T1.
NOTE: The data set WORK.T2 has 5000000 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 1.57 seconds
cpu time 1.35 seconds
271
272 data t2;
273
274 set t1;
275 array abc[*] abc01ef abc02ef abc03ef abc04ef;
276 s=1;
277 do i=1 to dim(abc);
278 s=s*missing(abc[i]);
279 end;
280 drop i;
281 run;
NOTE: There were 5000000 observations read from the data set WORK.T1.
NOTE: The data set WORK.T2 has 5000000 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 3.89 seconds
cpu time 1.81 seconds