<?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 SAS outliers output for multiple variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852540#M37470</link>
    <description>&lt;P&gt;Hello, I'm trying to output list of outliers for multiple numeric variables. Currently, I'm running the below code and merely replacing the vbox variable over and over again. Is there a macro to do this faster?&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is outlier with ids to be output for all numeric variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried&amp;nbsp;%LET numvar = var1 var2 var3 var4 var5... etc;&lt;/P&gt;&lt;P&gt;then in vbox &amp;amp;numvar. This is not working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ods output sgplot=boxplot_data;&lt;BR /&gt;proc sgplot data=data_a;&lt;BR /&gt;vbox &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;var 1&lt;/STRONG&gt;&lt;/FONT&gt; / datalabel=stid;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods excel file='C:..........xlsx'&amp;nbsp; ;&lt;BR /&gt;proc print data=boxplot_data;&lt;BR /&gt;run;&lt;BR /&gt;ods excel close;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data data_a;&lt;BR /&gt;input stid var1 var2 var3 var4 var5;&lt;BR /&gt;s1 0.1 1.9 2.7 4.6 3.9&lt;BR /&gt;s2 10.1 1.9 2.7 2.0 3.1&lt;BR /&gt;s3 0.1 1.2 2.4 3.9 6.9&lt;BR /&gt;s4 0.7 1.9 2.7 3.6 7.0&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Jan 2023 17:47:30 GMT</pubDate>
    <dc:creator>eawhit10</dc:creator>
    <dc:date>2023-01-06T17:47:30Z</dc:date>
    <item>
      <title>SAS outliers output for multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852540#M37470</link>
      <description>&lt;P&gt;Hello, I'm trying to output list of outliers for multiple numeric variables. Currently, I'm running the below code and merely replacing the vbox variable over and over again. Is there a macro to do this faster?&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is outlier with ids to be output for all numeric variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried&amp;nbsp;%LET numvar = var1 var2 var3 var4 var5... etc;&lt;/P&gt;&lt;P&gt;then in vbox &amp;amp;numvar. This is not working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ods output sgplot=boxplot_data;&lt;BR /&gt;proc sgplot data=data_a;&lt;BR /&gt;vbox &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;var 1&lt;/STRONG&gt;&lt;/FONT&gt; / datalabel=stid;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods excel file='C:..........xlsx'&amp;nbsp; ;&lt;BR /&gt;proc print data=boxplot_data;&lt;BR /&gt;run;&lt;BR /&gt;ods excel close;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data data_a;&lt;BR /&gt;input stid var1 var2 var3 var4 var5;&lt;BR /&gt;s1 0.1 1.9 2.7 4.6 3.9&lt;BR /&gt;s2 10.1 1.9 2.7 2.0 3.1&lt;BR /&gt;s3 0.1 1.2 2.4 3.9 6.9&lt;BR /&gt;s4 0.7 1.9 2.7 3.6 7.0&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2023 17:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852540#M37470</guid>
      <dc:creator>eawhit10</dc:creator>
      <dc:date>2023-01-06T17:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS outliers output for multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852545#M37471</link>
      <description>&lt;P&gt;It may help to define what you mean by "outlier".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An extension of your current approach would be reshaping the data, probably using Proc Transpose.&lt;/P&gt;
&lt;P&gt;For your example: Note corrections to your data step so that it will run.&lt;/P&gt;
&lt;PRE&gt;data data_a;
input stid $ var1 var2 var3 var4 var5;
datalines;
s1 0.1 1.9 2.7 4.6 3.9
s2 10.1 1.9 2.7 2.0 3.1
s3 0.1 1.2 2.4 3.9 6.9
s4 0.7 1.9 2.7 3.6 7.0
;

proc transpose data=data_a out=trans;
   by stid;
   var var1-var5;
run;

proc sgplot data=trans;
   vbox col1 /category=_name_ datalabel=stid;
run;
&lt;/PRE&gt;
&lt;P&gt;Depending on your data. You would have to sort the data by Stid if not already done so prior to the transpose.&lt;/P&gt;
&lt;P&gt;You could place any numeric variables on the Var statement in the Proc Transpose code. Too many may make the data set hard to display in a single graph panel. So may want to use more than one transpose with different variables.&lt;/P&gt;
&lt;P&gt;If you have duplicate values of your BY variable you may get more than one output variable for some variables.&lt;/P&gt;
&lt;P&gt;This is using defaults for the transpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2023 18:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852545#M37471</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-06T18:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS outliers output for multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852548#M37472</link>
      <description>&lt;P&gt;Use PROC MEANS which gives you output on many variables, all at once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means noprint data=data_a stackods n min max mean q1 median q3 p95 p5;
ods output summary=summary;
var var1-var5;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Agreeing with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;— you need a definition of outlier. SAS will compute whatever statistics you want, but determining what is and is not an outlier involves additional effort beyond computing statistics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/procstat/procstat_univariate_toc.htm" target="_self"&gt;PROC UNIVARIATE&lt;/A&gt; which gives you even a wider range of possible outputs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc univariate data=data_a;
var var1-var5;
output out=univ_out mean=m1-m5 std=std1-std5
   p5=p5_1-p5_5 p95=p95_1-p95_5;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2023 22:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852548#M37472</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-06T22:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS outliers output for multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852559#M37473</link>
      <description>&lt;P&gt;I don't want to transpose, there are too many variables. And proc sgplot included outliers for the one variable specified. (I assume they are using the standard definition: Outliers = Observations &amp;gt; Q3 + 1.5*IQR&amp;nbsp; or &amp;lt; Q1 – 1.5*IQR)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is that I want to find the outliers for more than one variable at once, not just doing the proc sgplots over and over for each variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So can I run proc sgplot to spit out multiple box plots/summaries in the vbox line with a macro of some sort?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2023 20:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852559#M37473</guid>
      <dc:creator>eawhit10</dc:creator>
      <dc:date>2023-01-06T20:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS outliers output for multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852570#M37474</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/358529"&gt;@eawhit10&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I don't want to transpose, there are too many variables. And proc sgplot included outliers for the one variable specified. (I assume they are using the standard definition: Outliers = Observations &amp;gt; Q3 + 1.5*IQR&amp;nbsp; or &amp;lt; Q1 – 1.5*IQR)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My problem is that I want to find the outliers for more than one variable at once, not just doing the proc sgplots over and over for each variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So can I run proc sgplot to spit out multiple box plots/summaries in the vbox line with a macro of some sort?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have given code that produces Q3, Q1 and IQR for all numeric variables at once. Macros are not needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2023 21:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852570#M37474</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-06T21:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS outliers output for multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852632#M37478</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/**********************************************
*** purpose : do loop for each var 
*** writen by : blueskyxyz
*** date: 2023-Jan-7
/**********************************************/
data data_a;
input stid $ var1 var2 var3 var4 var5;
datalines;
s1 0.1 1.9 2.7 4.6 3.9
s2 10.1 1.9 2.7 2.0 3.1
s3 0.1 1.2 2.4 3.9 6.9
s4 0.7 1.9 2.7 3.6 7.0
;

/*split with blank space*/
%LET numvar = var1 var2 var3 var4 var5;
%let cnt=%eval(%sysfunc(countc(&amp;amp;numvar," "))+1);
%put &amp;amp;cnt;

%macro loop_box();
%do i= 1 %to &amp;amp;cnt;
	%let var=%scan(&amp;amp;numvar.,&amp;amp;i.);
	%put &amp;amp;var.;

	ods output sgplot=boxplot_data;
	proc sgplot data=data_a;
		vbox &amp;amp;var. / datalabel=stid;
	run;

	ods excel file="F:\Mysas\sas_code\&amp;amp;var..xlsx"  ;
	proc print data=boxplot_data;
	run;
	ods excel close;
%end;
%mend;

%loop_box();&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Jan 2023 06:29:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852632#M37478</guid>
      <dc:creator>blueskyxyz</dc:creator>
      <dc:date>2023-01-07T06:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS outliers output for multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852633#M37479</link>
      <description>please refer to the code I post , maybe that's you want</description>
      <pubDate>Sat, 07 Jan 2023 06:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852633#M37479</guid>
      <dc:creator>blueskyxyz</dc:creator>
      <dc:date>2023-01-07T06:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS outliers output for multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852641#M37481</link>
      <description>If they are  multiple numeric variables. I think you could use Principal Component Analysis to find out outliers.&lt;BR /&gt;&lt;BR /&gt;Check &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt; blogs:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2019/03/25/geometry-multivariate-univariate-outliers.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2019/03/25/geometry-multivariate-univariate-outliers.html&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2012/03/23/the-curse-of-dimensionality.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2012/03/23/the-curse-of-dimensionality.html&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2012/02/02/detecting-outliers-in-sas-part-3-multivariate-location-and-scatter.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2012/02/02/detecting-outliers-in-sas-part-3-multivariate-location-and-scatter.html&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2012/01/27/detecting-outliers-in-sas-part-2-estimating-scale.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2012/01/27/detecting-outliers-in-sas-part-2-estimating-scale.html&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2012/01/20/detecting-outliers-in-sas-part-1-estimating-location.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2012/01/20/detecting-outliers-in-sas-part-1-estimating-location.html&lt;/A&gt;</description>
      <pubDate>Sat, 07 Jan 2023 09:01:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-outliers-output-for-multiple-variables/m-p/852641#M37481</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-01-07T09:01:52Z</dc:date>
    </item>
  </channel>
</rss>

