<?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: Winsorize a lot of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Winsorize-a-lot-of-variables/m-p/529028#M144475</link>
    <description>&lt;P&gt;If you have SAS/IML . That would be easy .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 do i=1 to 100;
  a=ceil(ranuni(1)*100);
  b=ceil(ranuni(2)*100);
  output;
 end;
 drop i;
run;


%let low=0.05 ;
%let high=0.95 ;

proc iml;
use have;
read all var _num_ into x[c=vname];
close have;
call qntl(q,x,{&amp;amp;low ,&amp;amp;high});

do i=1 to ncol(x);
 x[loc(x[,i]&amp;lt;q[1,i]),i]=q[1,i];
 x[loc(x[,i]&amp;gt;q[2,i]),i]=q[2,i];
end;

create want from x[c=vname];
append from x;
close want;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 22 Jan 2019 12:44:48 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-01-22T12:44:48Z</dc:date>
    <item>
      <title>Winsorize a lot of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Winsorize-a-lot-of-variables/m-p/528961#M144451</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to winsorize a lot of variables.&amp;nbsp; I searched and found there are so many macros out there. The macro I am currently using is this one:&amp;nbsp;&lt;A href="http://www.wrds.us/index.php/repository/view/sas_winsorize_macro" target="_blank"&gt;http://www.wrds.us/index.php/repository/view/sas_winsorize_macro&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I have more than 50 variables to be winsorized.&amp;nbsp; And the names of the 50 variables are not quite regular. I tried to quote the macro above in the following way. But it did not work out.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%winsor(dsetin=in, dsetout=out, byvar=none, vars=atg--umh, type=winsor, pctl=1 99)
 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I will appreciate it very much someone can help me out here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 03:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Winsorize-a-lot-of-variables/m-p/528961#M144451</guid>
      <dc:creator>daradanye</dc:creator>
      <dc:date>2019-01-22T03:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Winsorize a lot of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Winsorize-a-lot-of-variables/m-p/528966#M144453</link>
      <description>&lt;P&gt;You need to list the variables out in that macro instead of using the shortcut reference. Since it does what you want I suggest building a macro variable using SQL and passing that to the macro. Assuming your variables are ordered, which would need to be the case for your code to have worked, and that the first variable is 3 and the last is 103 then something like this would work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;

select name into :var_list separated by " "
from sashelp.vcolumn 
where upper(libname) = 'WORK' and upper(memname) = 'IN'
and varnum between 3 and 103;

quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can call the macro using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%winsor(dsetin=in, dsetout=out, byvar=none, vars=&amp;amp;var_list, type=winsor, pctl=1 99)&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32269"&gt;@daradanye&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to winsorize a lot of variables.&amp;nbsp; I searched and found there are so many macros out there. The macro I am currently using is this one:&amp;nbsp;&lt;A href="http://www.wrds.us/index.php/repository/view/sas_winsorize_macro" target="_blank"&gt;http://www.wrds.us/index.php/repository/view/sas_winsorize_macro&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I have more than 50 variables to be winsorized.&amp;nbsp; And the names of the 50 variables are not quite regular. I tried to quote the macro above in the following way. But it did not work out.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%winsor(dsetin=in, dsetout=out, byvar=none, vars=atg--umh, type=winsor, pctl=1 99)
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I will appreciate it very much someone can help me out here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 03:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Winsorize-a-lot-of-variables/m-p/528966#M144453</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-22T03:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: Winsorize a lot of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Winsorize-a-lot-of-variables/m-p/529028#M144475</link>
      <description>&lt;P&gt;If you have SAS/IML . That would be easy .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 do i=1 to 100;
  a=ceil(ranuni(1)*100);
  b=ceil(ranuni(2)*100);
  output;
 end;
 drop i;
run;


%let low=0.05 ;
%let high=0.95 ;

proc iml;
use have;
read all var _num_ into x[c=vname];
close have;
call qntl(q,x,{&amp;amp;low ,&amp;amp;high});

do i=1 to ncol(x);
 x[loc(x[,i]&amp;lt;q[1,i]),i]=q[1,i];
 x[loc(x[,i]&amp;gt;q[2,i]),i]=q[2,i];
end;

create want from x[c=vname];
append from x;
close want;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Jan 2019 12:44:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Winsorize-a-lot-of-variables/m-p/529028#M144475</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-01-22T12:44:48Z</dc:date>
    </item>
  </channel>
</rss>

