<?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: Proc univariate with observation values equal to zero removed in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647756#M193899</link>
    <description>&lt;P&gt;Thank you. This does exactly what I needed and works perfectly.&lt;/P&gt;</description>
    <pubDate>Thu, 14 May 2020 11:23:45 GMT</pubDate>
    <dc:creator>MsGeritO</dc:creator>
    <dc:date>2020-05-14T11:23:45Z</dc:date>
    <item>
      <title>Proc univariate with observation values equal to zero removed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647334#M193720</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have about 30 variables for which I amend outliers beyond the 97-percentile to the value of the individual 97-percentile cut-off. Identifying the 97-percentile I use proc univariate. The variables are all some kind of income variables and an income of zero should be excluded from the procedure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course, I could add (where var NE 0) in the data selection, but I would rather not want to repeat the code 30+ times.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anybody help? My internet research hasn't delivered any solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much in advance.&lt;/P&gt;&lt;P&gt;Gerit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 May 2020 07:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647334#M193720</guid>
      <dc:creator>MsGeritO</dc:creator>
      <dc:date>2020-05-13T07:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc univariate with observation values equal to zero removed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647380#M193746</link>
      <description>&lt;P&gt;A macro would work here. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis;
    proc contents data=have noprint out=_contents_;
    run;
    proc sql noprint;
        select name into :names separated by ' ' from _contents_;
    quit;
    %do i=1 %to %sqlobs;
        %let thisvar=%scan(&amp;amp;names,&amp;amp;i,%str( ));
          /* Add any other options to PROC UNIVARIATE that you want */
          proc univariate data=have(where=(&amp;amp;thisvar^=0));
               var &amp;amp;thisvar;
          run;
      %end;
%mend;
%dothis&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 May 2020 10:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647380#M193746</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-13T10:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc univariate with observation values equal to zero removed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647397#M193762</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150610"&gt;@MsGeritO&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also include the DATA step into the macro where you "cap" the variables at their respective 97th percentiles:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro capvar(data=,     /* input dataset */
              out=,      /* output dataset */
              varlist=,  /* list of numeric variables to be capped */
              pctl=      /* cut-off percentile (e.g. 97) */
              );
%local i nv var;
%let nv=%sysfunc(countw(&amp;amp;varlist));

/* Compute percentiles */
%do i=1 %to &amp;amp;nv;
  %let var=%scan(&amp;amp;varlist,&amp;amp;i);
  proc univariate data=&amp;amp;data noprint;
  where &amp;amp;var ne 0;
  var &amp;amp;var;
  output out=_p&amp;amp;i pctlpts=&amp;amp;pctl pctlpre=_ pctlname=pctl;
  run;
%end;

/* Write percentiles to macro variables */
data _null_;
set _p1-_p&amp;amp;nv;
call symputx(cat('_p',_n_),_pctl,'L');
run;

/* Create output dataset */
data &amp;amp;out;
set &amp;amp;data;
%do i=1 %to &amp;amp;nv;
  %let var=%scan(&amp;amp;varlist,&amp;amp;i);
  if &amp;amp;var&amp;gt;&amp;amp;&amp;amp;_p&amp;amp;i then &amp;amp;var=&amp;amp;&amp;amp;_p&amp;amp;i;
%end;
run;
%mend capvar;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example call of the macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%capvar(data=sashelp.heart, out=want, varlist=Weight Diastolic Systolic, pctl=97);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 May 2020 10:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647397#M193762</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-05-13T10:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc univariate with observation values equal to zero removed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647485#M193803</link>
      <description>&lt;P&gt;Temporary data set where you replace the 0 values with missing.&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data temp;
   set have;
   array inc &amp;lt;list of income variable names goes here&amp;gt;;
   do _i_ = 1 to dim(inc);
      if inc[_i_]=0 then [_i_]=.;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;And use that set for proc univariate to find your outliers.&lt;/P&gt;</description>
      <pubDate>Wed, 13 May 2020 14:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647485#M193803</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-13T14:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc univariate with observation values equal to zero removed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647756#M193899</link>
      <description>&lt;P&gt;Thank you. This does exactly what I needed and works perfectly.&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 11:23:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647756#M193899</guid>
      <dc:creator>MsGeritO</dc:creator>
      <dc:date>2020-05-14T11:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Proc univariate with observation values equal to zero removed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647760#M193900</link>
      <description>Thank you Paige Miller for your help. I appreciate any pointers. I thought about macros, but I am not so firm here. So this is a good help.</description>
      <pubDate>Thu, 14 May 2020 11:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647760#M193900</guid>
      <dc:creator>MsGeritO</dc:creator>
      <dc:date>2020-05-14T11:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Proc univariate with observation values equal to zero removed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647761#M193901</link>
      <description>Thank you ballardw for your post. It is so nice that people help. I thought about something similar, but refrained as I needed to code which values are "." because they are really missing and which are "." because they are zero, since this information is needed at a later state. Of course this is possible, too, just again more complicated &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; Thank you nonetheless.</description>
      <pubDate>Thu, 14 May 2020 11:48:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-univariate-with-observation-values-equal-to-zero-removed/m-p/647761#M193901</guid>
      <dc:creator>MsGeritO</dc:creator>
      <dc:date>2020-05-14T11:48:28Z</dc:date>
    </item>
  </channel>
</rss>

