Hello Everyone:
I am working with a SAS macro to winsorize my data (please see attached). The SAS macro is below. When I run the program, it appears to be running okay (no error is generated), however there is no output. Could you help me identify what might be the problem? I tried closing the SAS program and opening back again, but it did not help.
Thank you so much!
/******************************************************************************* http://www.byuaccounting.net/mediawiki/images/5/51/WinsorizeMacro.txt Winsorize macro Can winsorize or trim at specified percentiles; dsetout = leave blank to overwrite dsetin byvar = none for no byvar (trims/winsorizes pooled sample) type = delete/winsor ex: %winsor(dsetin=mydata, dsetout=mydata2, byvar=year, vars=assets earnings, pctl=0 98); winsorizes by year at 98%, puts resulting dataset into mydata2
%winsor(dsetin=mydata, vars=assets earnings, type=delete); trims pooled sample at 1% and 99%, puts resulting dataset back into mydata ********************************************************************************/
%macro winsor(dsetin=sasregrr, dsetout=aregrr, byvar=none, vars=equal, type=winsor, pctl=15 85);
%if &dsetout = %then %let dsetout = &dsetin; %let varL=; %let varH=; %let xn=1;
%do %until ( %scan(&vars,&xn)= ); %let token = %scan(&vars,&xn); %let varL = &varL &token.L; %let varH = &varH &token.H; %let xn=%EVAL(&xn + 1); %end;
%let xn=%eval(&xn-1);
data xtemp; set &dsetin; run;
%let dropvar = ; %if &byvar = none %then %do;
data xtemp; set xtemp; xbyvar = 1; run;
%let byvar = xbyvar; %let dropvar = xbyvar;
%end;
proc sort data = xtemp; by &byvar; run;
proc univariate data = xtemp noprint; by &byvar; var &vars; output out = xtemp_pctl PCTLPTS = &pctl PCTLPRE = &vars PCTLNAME = L H; run;
data &dsetout; merge xtemp xtemp_pctl; by &byvar; array trimvars{&xn} &vars; array trimvarl{&xn} &varL; array trimvarh{&xn} &varH;
do xi = 1 to dim(trimvars);
%if &type = winsor %then %do; if trimvars{xi} ne . then do; if (trimvars{xi} < trimvarl{xi}) then trimvars{xi} = trimvarl{xi}; if (trimvars{xi} > trimvarh{xi}) then trimvars{xi} = trimvarh{xi}; end; %end;
%else %do; if trimvars{xi} ne . then do; if (trimvars{xi} < trimvarl{xi}) then delete; if (trimvars{xi} > trimvarh{xi}) then delete; end; %end;
end; drop &varL &varH &dropvar xi; run;
%mend winsor;
... View more