It looks like your saying echos my point.
Then why do you use count as a counter, we should use _n_, right? So, count is not used at all, code should look like this:
data tmp2 tmp3;
set tmp;
array acc(*) accrual_1 accrual_2 accrual_3 accrual_4;
do _n_=1 to dim(acc);
if acc(_n_) in (1,2,3,4,5,6) then count+1;
end;
/* count is the number of variables that have same condition */
if _n_=4 then output tmp2;
else output tmp3;
run;
Am I right?
You can't replace count with _n_ in the sample code. count is used to calculate how many variables meet your condition (in (1,2,3,4,5,6)). In my sample code, if all the four variables are in (1,2,3,4,5,6) then output to tmp2(count will be 4) , if one or more variables are not in (1,2,3,4,5,6) then output to tmp3 (count will be less then 4).
%macro multiVin(vars= ,incond= ,link=or ,output= ,elsout=);
%if %str(&link)=%str(or) %then %let ocond=%str(>1);
%else %let ocond=dim(acc&sysindex);
array acc&sysindex
array cnt&sysindex[1] _temporary_;
cnt&sysindex[1]=0;
do _n_=1 to dim(acc&sysindex);
if acc&sysindex[_n_] in (&incond) then cnt&sysindex[1]+1;
end;
if cnt&sysindex[1]=&ocond then output &output;
%if &elsout>. %then %do;
else output &elsout;
%end;
%mend;
data foo;
input accrual_1-accrual_4;
cards;
1 2 1 2
12 4 12 4
3 5 3 5
9 9 9 9
;
run;
data bar;
set foo;
%multiVin(vars=accrual_1-accrual_4 ,incond=%str(1,2,3,4,5,6) ,link=and);
run;
accrual_1 accrual_2 accrual_3 accrual_4
1 2 1 2
3 5 3 5
data bar;
set foo;
%multiVin(vars=accrual_1-accrual_4 ,incond=%str(1,2,3,4,5,6) ,link=or);
run;
accrual_1 accrual_2 accrual_3 accrual_4
1 2 1 2
12 4 12 4
3 5 3 5
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.