|
The basic problem is that macros are not SAS.
I think you want your macro to accept 1) a list of variables, 2) a limit,
and 3) a result variable. I think you want the result variable set to the
mean of the list IF AND ONLY IF at least limit variables are missing. NOTE:
I would expect a test for FEWER than limit missing values, but the code is
clear.
Unfortunately, the macro is only evaluated once per job, not once per
observation. When the macro resolves, there is no current observation from
which to count missing values.
Perhaps you want the macro to generate datastep code, using macro syntax
like:
IF NMISS(&varlist) GE &min_num
THEN &meanvar = MEAN(&varlist);
ELSE &meanvar=.;
> ----------
> 1010
> 1011 %macro miss(varlist=, min_num=, meanvar=);
> 1012
> 1013 %if nmiss(&varlist) GE %eval(&min_num) %then %do;
> 1014 %let &meanvar = mean(&varlist); %end;
> 1015 %else %let &meanvar =" ";
> 1016
> 1017 %mend miss;
> 1018
> 1019
> 1020 data test1;
> 1021
> 1022 set transcq;
> 1023
> 1024 %miss(varlist= %str(ncq41, ncq42), min_num=1, meanvar=M_bp);
> MLOGIC(MISS): Beginning execution.
> MLOGIC(MISS): Parameter VARLIST has value ncq41 ncq42
> MLOGIC(MISS): Parameter MIN_NUM has value 1
> MLOGIC(MISS): Parameter MEANVAR has value M_bp
> SYMBOLGEN: Macro variable VARLIST resolves to ncq41, ncq42
> SYMBOLGEN: Some characters in the above value which were subject to macro
> quoting have been unquoted for printing.
> ERROR: Required operator not found in expression: nmiss(&varlist) GE
> %eval(&min_num)
> The
> SAS
> System
>
> ERROR: The macro will stop executing.
> MLOGIC(MISS): Ending execution.
> 1025
> 1026 run;
>
> NOTE: The data set WORK.TEST1 has 4 observations and 121 variables.
> NOTE: The DATA statement used 0.05 seconds.
>
>
> 1027
> 1028 endsas;
>
> ERROR: Errors printed on pages 9,10.
>
> NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
>
|