windorize without replacing missing data

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

windorize without replacing missing data

Hi

I need to windorize data. I am using the following code to do so. However, it replaces the missing values too.

proc univariate data=acc_data noprint;

var cash CF Lev Q DVC AT B2M LagAT;

output out=_winsor   pctlpts=1 99     pctlpre=__cash __CF __Lev __Q __DVC __AT __B2M __LagAT;

run;

data acc_data_win (drop=_Smiley Happy;

set acc_data;

if _n_=1 then set _winsor;

array wlo  {*} __cash1 __CF1 __Lev1 __Q1 __DVC1 __AT1 __B2M1 __LagAT1;

array whi  {*} __cash99 __CF99 __Lev99 __Q99 __DVC99 __AT99 __B2M99 __LagAT99;

array wval {*} wcash wCF wLev wQ wDVC wAT wB2M wLagAT;

array val   {*} cash CF Lev Q DVC AT B2M LagAT;

do _V=1 to dim(val);

end;

run;

Any suggestion to avoid replacing missing values and windorize only the non missing values.

Thanks in advance.

Regards,

Waqar


Accepted Solutions
Solution
‎06-19-2013 10:53 AM
Respected Advisor
Posts: 4,659

Re: windorize without replacing missing data

To avoid replacing missing values, you must exclude missing values from the lower range (they rank as minus infinity) :

do _V=1 to dim(val);

     if . < val{_V} < wlo{_V} then val{_V} = wlo{_V};

     else if val{_V} > whi{_V} then val{_V} = whi{_V};

     end;

you might need a retain statement on the _winsor variables.

PG

PG

View solution in original post


All Replies
Solution
‎06-19-2013 10:53 AM
Respected Advisor
Posts: 4,659

Re: windorize without replacing missing data

To avoid replacing missing values, you must exclude missing values from the lower range (they rank as minus infinity) :

do _V=1 to dim(val);

     if . < val{_V} < wlo{_V} then val{_V} = wlo{_V};

     else if val{_V} > whi{_V} then val{_V} = whi{_V};

     end;

you might need a retain statement on the _winsor variables.

PG

PG
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 203 views
  • 0 likes
  • 2 in conversation