jackbt123 发表于 2011-7-5 09:38 
如何判断多个变量的值是否等于一个常量
IF(A1 = 1 OR A2 = 1 OR A3 = 1 OR ...... OR A100 = 1)
THEN DUMMAY = 1;
ELSE DUMMAY = 0;
More efficient way
Array, Do Loop and Until or While
ARRAY ARRAY_TEMP {*} A1 - A100;
DUMMAY = 0;
DO i = 1 TO 100 WHILE (DUMMAY = 0);
IF ARRAY_TEMP {i} = 1 THEN DUMMAY = 1;
END;
Question: other solutions?
More efficient way turns out much slower than a seemingly dumb approach(3 times faster). It is faster in coding not in executing. See the log below.
753 data t1;
754 array A(100);
755 do i=1 to 1e6;
756 do j=1 to dim(A);
757 A[j]=ceil(ranuni(123)*1000);
758 end;
759 output;
760 end;
761 keep A:;
762 run;
NOTE: The data set WORK.T1 has 1000000 observations and 100 variables.
NOTE: DATA statement used (Total process time):
real time 13.22 seconds
cpu time 9.90 seconds
763
764 %macro ifcondition(k);
765 %do i=1 %to &k;
766 %if &i=1 %then A&i=1;
767 %else OR A&i=1;
768 %end;
769 %mend;
770
771
772 data _null_;
773 set t1;
774 if %ifcondition(100)
775 THEN DUMMAY = 1;
776 ELSE DUMMAY = 0;
777 run;
NOTE: There were 1000000 observations read from the data set WORK.T1.
NOTE: DATA statement used (Total process time):
real time 0.99 seconds
cpu time 0.63 seconds
778
779
780 data _null_;
781 set t1;
782 ARRAY ARRAY_TEMP {*} A1 - A100;
783 DUMMAY = 0;
784 DO i = 1 TO 100 WHILE (DUMMAY = 0);
785 IF ARRAY_TEMP {i} = 1 THEN DUMMAY = 1;
786 END;
787 run;
NOTE: There were 1000000 observations read from the data set WORK.T1.
NOTE: DATA statement used (Total process time):
real time 2.23 seconds
cpu time 1.74 seconds