Hi, SAS experts, I'm trying to use call execute and %macro to trim multiple variables at the 99 percentile and 1st percentile. I found a very helpful post from this forum: https://communities.sas.com/t5/General-SAS-Programming/SAS-MACRO-Capping-Outliers-for-Dollar-amount-variables/td-p/335040# I followed their steps and it did work. However, in their code, the new data set directly replaces the previous data set, and the created variables directly replace the original variables. I would like to tweak their code by creating a new data set and new variables. I'm using their code to demonstrate below: However, I got error messages saying "ERROR: The keyword parameter DSET2 was not defined with the macro. ERROR: The keyword parameter VAR2 was not defined with the macro." What I can do to achieve the result I want? Thank you very much in advance! *Calculate IQR and first/third quartiles;
proc means data=sashelp.class stackods n qrange p1 p99;
var weight height;
ods output summary=ranges;
run;
*create data with outliers to check;
data capped;
set sashelp.class;
if name='Alfred' then weight=220;
if name='Jane' then height=-30;
run;
*macro to cap outliers;
%macro cap(dset=,dset2=, var=,var2=, lower=, upper=);/* here I added dset2 and var2*/
data &dset2;/* here I tweaked their code, hoping to create a new data set with a new set of variables*/
set &dset;
if &var>&upper then &var2=&upper;
if &var<&lower then &var2=&lower;
run;
%mend;
*create cutoffs and execute macro for each variable;
data cutoffs;
set ranges;
lower=p1;
upper=p99;
string = catt('%cap(dset=capped, dset2=new, var=, var2=', variable, ", lower=", lower, ", upper=", upper ,");");/* here I added dset2 and var2*/
call execute(string);
run;
... View more