Outliers for all numerical values to mean SAS

I am working in SAS with a dataset with a lot of numeric values which I have standardised as follows:

 proc standard data=df mean=0 std=1
 out=df;       
 run;

Is there any easy way to deal with outliers (+/- 3standard deviation) for all numeric values? Ideally I would want to change all of those to + or - 3x standard deviation, or in worst case remove them.

1 answer

  • answered 2018-03-11 17:32 DCR

    You have to run through the data twice. There are may ways you can adjust your output. Here's a simple way using a datastep:

    Assuming your dataset has a standardized variable called 'test':

    Data adjusted;
    set df;
    if test > 3 then test=3;
    if test < -3 then test =-3;
    run;
    

    just remember your new dataset will no longer have a mean of 0 and a standard deviation of 1