My code is similar to below. I have a lot of different datasets and %if &dsn in (CMD DEM DV2) doesn't seem to work. Is there a different command that does the same thing?
%macro Counts(dsn, varlist);
data &dsn.1;
set an.&dsn_an;
%if &dsn= CMD|&dsn= DEM|&dsn= DV2 %then %do;
where protseg in ('A' 'B');
%end;
array vars{*} &varlist.;
num=0; den=0;
do i=1 to dim(vars);
if vars{i} in ("a" "d" "g" "j") then den = sum(den, 1); /*denominator*/
if vars{i} in ("j") then num = sum(num, 1); /*numerator*/
end;
run;
%mend;
If you want the macro processor to treat IN as an operator you need to tell it that with the MINOPERATOR option.
But if you are going to use IN as an operator inside a macro definition then it is best to set that option on %MACRO statement instead of depending on the whims of the user that is calling the macro.
%macro Counts(dsn, varlist) / minoperator mindelimter=' ';
data &dsn.1;
set an.&dsn_an;
%if &dsn in CMD DEM DV2 %then %do;
where protseg in ('A' 'B');
%end;
array vars{*} &varlist.;
num=0; den=0;
do i=1 to dim(vars);
/*denominator*/
if vars{i} in ("a" "d" "g" "j") then den = sum(den, 1);
/*numerator*/
if vars{i} in ("j") then num = sum(num, 1);
end;
run;
%mend Counts;
PS Make it easier to read the code by placing comments about what the code is going to do BEFORE the code instead of afterwords.
See the MINOPERATOR option and the MINDELIMITER option.
If you want the macro processor to treat IN as an operator you need to tell it that with the MINOPERATOR option.
But if you are going to use IN as an operator inside a macro definition then it is best to set that option on %MACRO statement instead of depending on the whims of the user that is calling the macro.
%macro Counts(dsn, varlist) / minoperator mindelimter=' ';
data &dsn.1;
set an.&dsn_an;
%if &dsn in CMD DEM DV2 %then %do;
where protseg in ('A' 'B');
%end;
array vars{*} &varlist.;
num=0; den=0;
do i=1 to dim(vars);
/*denominator*/
if vars{i} in ("a" "d" "g" "j") then den = sum(den, 1);
/*numerator*/
if vars{i} in ("j") then num = sum(num, 1);
end;
run;
%mend Counts;
PS Make it easier to read the code by placing comments about what the code is going to do BEFORE the code instead of afterwords.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.