<?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 for top n largest values for multiple variables (columns) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927308#M364949</link>
    <description>&lt;P&gt;Add the NOTSORTED option to the BY statement in the PROC TRANSPOSE step if your variables are not in the dataset in alphabetical order.&lt;/P&gt;</description>
    <pubDate>Tue, 07 May 2024 13:40:09 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-05-07T13:40:09Z</dc:date>
    <item>
      <title>Proc Univariate for top n largest values for multiple variables (columns)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927289#M364937</link>
      <description>&lt;P&gt;I have a data set with multiple variables (columns).&amp;nbsp; I'm trying to get the top 10 values of each variable.&amp;nbsp; However, I would like the output to be in a new dataset with a new variable called: variable_names.&amp;nbsp; The row shows the top 10 values from smallest to largest.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data below is just an example.&amp;nbsp; I have more than 4 input variables.&amp;nbsp; Here, I am just looking at the top 3.&amp;nbsp; For a bigger data set, I may look at the top 10.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;data example;&lt;BR /&gt;input a b c d;&lt;BR /&gt;datalines;&lt;BR /&gt;100 120 123 140&lt;BR /&gt;12 23 43 42&lt;BR /&gt;12 12 23 23&lt;BR /&gt;5 7 5 2&lt;BR /&gt;80 88 98 2&lt;BR /&gt;3 4 101 4&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let nTop = 3;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;proc univariate data = new_data NExtrObs=&amp;amp;nTop;&lt;BR /&gt;ods select ExtremeObs;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The proc univariate gives a separate output for each.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;The UNIVARIATE Procedure&lt;/DIV&gt;&lt;DIV class=""&gt;Variable: a&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV align="left"&gt;Extreme Observations&lt;/DIV&gt;&lt;DIV align="left"&gt;Lowest&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Highest&lt;/DIV&gt;&lt;DIV align="left"&gt;Value Obs Value Obs&lt;/DIV&gt;&lt;DIV align="left"&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/DIV&gt;&lt;DIV align="left"&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 80&amp;nbsp; &amp;nbsp; 5&lt;/DIV&gt;&lt;DIV align="left"&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; 1&lt;/DIV&gt;&lt;DIV align="left"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV align="left"&gt;&lt;P&gt;I would like to create a new data set where output with column names: Variables and the top values.&amp;nbsp; For example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Variables&amp;nbsp; &amp;nbsp;Top1 Top2 Top3&lt;/P&gt;&lt;P&gt;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; 80&amp;nbsp; &amp;nbsp; &amp;nbsp; 100&lt;/P&gt;&lt;P&gt;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 23&amp;nbsp; &amp;nbsp; &amp;nbsp; 88&amp;nbsp; &amp;nbsp; &amp;nbsp; 120&lt;/P&gt;&lt;P&gt;c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 07 May 2024 09:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927289#M364937</guid>
      <dc:creator>kk13</dc:creator>
      <dc:date>2024-05-07T09:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Univariate for top n largest values for multiple variables (columns)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927292#M364938</link>
      <description>&lt;P&gt;I forgot to add that I would like to look at the top 10 distinct values.&amp;nbsp; The proc univariate gives does not give out the top distinct values.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2024 10:06:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927292#M364938</guid>
      <dc:creator>kk13</dc:creator>
      <dc:date>2024-05-07T10:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Univariate for top n largest values for multiple variables (columns)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927293#M364939</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150926"&gt;@kk13&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_univariate_syntax01.htm#procstat.univariate.proc_nextrval" target="_blank" rel="noopener"&gt;NEXTR&lt;STRONG&gt;VAL&lt;/STRONG&gt;= option&lt;/A&gt;:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nTop = 3;  
ods select none;
ods output ExtremeValues=extrval(keep=varname high);
proc univariate data=example NExtrVal=&amp;amp;nTop;
run;
ods select all;

proc transpose data=extrval out=want(drop=_:) prefix=Top;
by varname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2024 10:20:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927293#M364939</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-05-07T10:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Univariate for top n largest values for multiple variables (columns)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927299#M364942</link>
      <description>Is there an option to get the number of count in the top 3. For example, the variable a has 2 counts of 12, 1 count of 80, and 1 count of 100.</description>
      <pubDate>Tue, 07 May 2024 13:04:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927299#M364942</guid>
      <dc:creator>kk13</dc:creator>
      <dc:date>2024-05-07T13:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Univariate for top n largest values for multiple variables (columns)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927308#M364949</link>
      <description>&lt;P&gt;Add the NOTSORTED option to the BY statement in the PROC TRANSPOSE step if your variables are not in the dataset in alphabetical order.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2024 13:40:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927308#M364949</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-07T13:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Univariate for top n largest values for multiple variables (columns)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927309#M364950</link>
      <description>&lt;P&gt;The count is there (remove the KEEP= dataset option from the ODS OUTPUT statement).&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2024 13:41:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927309#M364950</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-07T13:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Univariate for top n largest values for multiple variables (columns)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927313#M364951</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150926"&gt;@kk13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Is there an option to get the number of count in the top 3. For example, the variable a has 2 counts of 12, 1 count of 80, and 1 count of 100.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can keep the additional variable &lt;FONT face="courier new,courier"&gt;HighFreq&lt;/FONT&gt; in the EXTRVAL dataset and then use PROC SUMMARY instead of PROC TRANSPOSE to create dataset WANT:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#999999"&gt;%let nTop = 3;  
ods select none;
ods output ExtremeValues=extrval(keep=varname high &lt;FONT color="#000000"&gt;&lt;STRONG&gt;highfreq&lt;/STRONG&gt;&lt;/FONT&gt;);
proc univariate data=example NExtrVal=&amp;amp;nTop;
run;
ods select all;&lt;/FONT&gt;

&lt;STRONG&gt;proc summary data=extrval;
by varname;
output out=want(drop=_:) idgroup(out[&amp;amp;nTop] (high:)=);
run;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2024 13:56:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Univariate-for-top-n-largest-values-for-multiple-variables/m-p/927313#M364951</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-05-07T13:56:52Z</dc:date>
    </item>
  </channel>
</rss>

