<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Winsorization in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391743#M94161</link>
    <description>Sounds silly but how can I find that ?</description>
    <pubDate>Wed, 30 Aug 2017 06:34:39 GMT</pubDate>
    <dc:creator>Theo_Gh</dc:creator>
    <dc:date>2017-08-30T06:34:39Z</dc:date>
    <item>
      <title>Winsorization</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391724#M94157</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an accounting data and looking forward to winsorizing the variables. I checked and there seems to be a number of ways to do it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please is there a most efficient and generally acceptable way of winsorizing accounting data with a code or macro ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 04:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391724#M94157</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-08-30T04:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: Winsorization</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391730#M94158</link>
      <description>&lt;P&gt;Check the &lt;SPAN class=" AAterm "&gt;WINSORIZED option in proc univariate.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 05:05:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391730#M94158</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-08-30T05:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: Winsorization</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391742#M94160</link>
      <description>&lt;P&gt;Rick Wicklin has two great articles on the subject&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2015/07/15/winsorize-data.html" target="_blank"&gt;How to Winsorize data in SAS&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2017/02/08/winsorization-good-bad-and-ugly.html" target="_blank"&gt;Winsorization: The good, the bad, and the ugly&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 06:28:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391742#M94160</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-08-30T06:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: Winsorization</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391743#M94161</link>
      <description>Sounds silly but how can I find that ?</description>
      <pubDate>Wed, 30 Aug 2017 06:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391743#M94161</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-08-30T06:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Winsorization</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391744#M94162</link>
      <description>&lt;P&gt;In the &lt;A href="http://support.sas.com/documentation/cdl/en/procstat/66703/HTML/default/viewer.htm#procstat_univariate_syntax01.htm" target="_blank"&gt;PROC UNIVARIATE&amp;nbsp;Documentation&lt;/A&gt;&amp;nbsp;and as an example in the first article that I link to in my previous post &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 06:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391744#M94162</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-08-30T06:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Winsorization</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391797#M94181</link>
      <description>&lt;P&gt;Please bear with me. I have a dataset with variables like div size lev roa etc which I want to winsorize. I have gvkey as the main identifier.&lt;/P&gt;&lt;P&gt;I have tried using the code below but to no avail. I'm sure I'm not filling out the code well. Please note that this is a sample code I'm trying to use. Your help is very much appreciated!&lt;/P&gt;&lt;P&gt;The macro is :&lt;/P&gt;&lt;PRE&gt;%macro winsor(dsetin=, dsetout=, byvar=none, vars=, type=winsor, pctl=1 99);

%if &amp;amp;dsetout = %then %let dsetout = &amp;amp;dsetin;
    
%let varL=;
%let varH=;
%let xn=1;

%do %until ( %scan(&amp;amp;vars,&amp;amp;xn)= );
    %let token = %scan(&amp;amp;vars,&amp;amp;xn);
    %let varL = &amp;amp;varL &amp;amp;token.L;
    %let varH = &amp;amp;varH &amp;amp;token.H;
    %let xn=%EVAL(&amp;amp;xn + 1);
%end;

%let xn=%eval(&amp;amp;xn-1);

data xtemp;
    set &amp;amp;dsetin;
    run;

%if &amp;amp;byvar = none %then %do;

    data xtemp;
        set xtemp;
        xbyvar = 1;
        run;

    %let byvar = xbyvar;

%end;

proc sort data = xtemp;
    by &amp;amp;byvar;
    run;

proc univariate data = xtemp noprint;
    by &amp;amp;byvar;
    var &amp;amp;vars;
    output out = xtemp_pctl PCTLPTS = &amp;amp;pctl PCTLPRE = &amp;amp;vars PCTLNAME = L H;
    run;

data &amp;amp;dsetout;
    merge xtemp xtemp_pctl;
    by &amp;amp;byvar;
    array trimvars{&amp;amp;xn} &amp;amp;vars;
    array trimvarl{&amp;amp;xn} &amp;amp;varL;
    array trimvarh{&amp;amp;xn} &amp;amp;varH;

    do xi = 1 to dim(trimvars);

        %if &amp;amp;type = winsor %then %do;
            if not missing(trimvars{xi}) then do;
              if (trimvars{xi} &amp;lt; trimvarl{xi}) then trimvars{xi} = trimvarl{xi};
              if (trimvars{xi} &amp;gt; trimvarh{xi}) then trimvars{xi} = trimvarh{xi};
            end;
        %end;

        %else %do;
            if not missing(trimvars{xi}) then do;
              if (trimvars{xi} &amp;lt; trimvarl{xi}) then delete;
              if (trimvars{xi} &amp;gt; trimvarh{xi}) then delete;
            end;
        %end;

    end;
    drop &amp;amp;varL &amp;amp;varH xbyvar xi;
    run;

%mend winsor;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;Ple&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 12:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391797#M94181</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-08-30T12:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Winsorization</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391875#M94208</link>
      <description>&lt;P&gt;If you're just starting to learn SAS do not try to learn macros at first. Figure things out in a data step first. You'll get to macro and they definitely help but you likely won't be able to modify them or even really test them to ensure they're correct at this point.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you've shown is macro code, sort of like a function in R, but you haven't actually called it yet. You need to execute the macro and pass the correct parameters in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a very simplified example that calculates the winsorized mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro winsor_mean(dset=, var=, winsor=);

	proc univariate data=&amp;amp;dset winsor=5;
		var &amp;amp;var;
	run;

%mend;

%winsor_mean(dset=sashelp.class, var=weight);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 14:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/391875#M94208</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-30T14:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Winsorization</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/392305#M94372</link>
      <description>Thank you very much</description>
      <pubDate>Thu, 31 Aug 2017 17:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Winsorization/m-p/392305#M94372</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-08-31T17:46:07Z</dc:date>
    </item>
  </channel>
</rss>

