<?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: Print 20 Highest Obs for all variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Print-20-Highest-Obs-for-all-variables/m-p/632683#M77835</link>
    <description>&lt;P&gt;You can get this information from PROC UNIVARIATE. If you don't mind also getting the lowest values, use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc univariate data=Sashelp.Cars nextrobs=20;
   ods select ExtremeObs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't want the low values, write the ExtremeObs table to a data set and use PROC PRINT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
proc univariate data=Sashelp.Cars nextrobs=20;
   ods output ExtremeObs=XOBs;
run;
ods select all;

proc print data=XObs noobs;
  by VarName notsorted;
  var High HighObs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Mar 2020 14:45:47 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2020-03-17T14:45:47Z</dc:date>
    <item>
      <title>Print 20 Highest Obs for all variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Print-20-Highest-Obs-for-all-variables/m-p/632664#M77828</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is how to create a macro/loop that prints the 20&amp;nbsp;observations with highest value&amp;nbsp;for each variable in a dataset.&lt;/P&gt;&lt;P&gt;Obviously this can be done for each variable separately using sort and print, but seems to me that there should be a more elegant way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 13:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Print-20-Highest-Obs-for-all-variables/m-p/632664#M77828</guid>
      <dc:creator>Dor</dc:creator>
      <dc:date>2020-03-17T13:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Print 20 Highest Obs for all variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Print-20-Highest-Obs-for-all-variables/m-p/632667#M77829</link>
      <description>&lt;P&gt;Using macro makes code hardly more elegant, in most cases macro code is not necessary at all, but seems to be easier than trying to understand basic group-procession. Could you please post an example dataset and explain what you exactly expect as result?&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 13:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Print-20-Highest-Obs-for-all-variables/m-p/632667#M77829</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-03-17T13:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Print 20 Highest Obs for all variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Print-20-Highest-Obs-for-all-variables/m-p/632670#M77831</link>
      <description>&lt;P&gt;Sure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, a dataset with two variables, age and income, with 100 observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Example;
    INPUT age income;
   DATALINES;
22 1000
23 1200
…
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to print the 20 observations with highest values, in this example highest, 2 outputs once for age and then for income, each time with the 20 highest values in each.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this makes it clear, and thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 14:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Print-20-Highest-Obs-for-all-variables/m-p/632670#M77831</guid>
      <dc:creator>Dor</dc:creator>
      <dc:date>2020-03-17T14:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Print 20 Highest Obs for all variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Print-20-Highest-Obs-for-all-variables/m-p/632672#M77832</link>
      <description>&lt;P&gt;Well, not that clear ... the following steps list the top 5 values of the numeric vars in sashelp.class:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=sashelp.class;
   output out=top5(drop=_type_ _freq_) idgroup(max(Age) max(Weight) max(Height) out[5](Age Weight Height)=);
run;

proc transpose data=work.top5 out=work.transposed;
run;

data work.optimized;
   set work.transposed(rename=(_name_ = varName col1=value));
   
   length position 8;
   label varName = " ";

   position = input(compress(varName,,'dk'), 2.);
   varName = scan(varName, 1, '_');
run;

proc sort data=work.optimized out=work.sorted;
   by varName position;
run;


options nobyline;

title "Top 5 of ""#byval1""";

proc print data=work.sorted noobs;
   by varName;
run;

title;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Mar 2020 14:11:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Print-20-Highest-Obs-for-all-variables/m-p/632672#M77832</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-03-17T14:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Print 20 Highest Obs for all variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Print-20-Highest-Obs-for-all-variables/m-p/632674#M77833</link>
      <description>&lt;P&gt;Which observation you want in case there is more than one with save value of a variable ?&lt;/P&gt;
&lt;P&gt;Are variables all numeric? do you want to include alphabetic variables ?&lt;/P&gt;
&lt;P&gt;How many variables do you have ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use &lt;STRONG&gt;proc summary&lt;/STRONG&gt; to create a temporary dataset with all max values, then subset those observations&lt;/P&gt;
&lt;P&gt;with equal values to the temporary file variables, finaly select 20 observations. It may come out with less then 20 obs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have missing noprint;
var &amp;lt;variable names separated by space, numeric only &amp;gt;;
output out=temp(drop=count _type_) max=;
run;

proc sql;
   create table want as
   select a.* from have as a
   left join temp as b on
       a.var1 = b.var1 or
       a.var2 = b.var2 or
       ..... /* up to last variable in temp */
; quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 14:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Print-20-Highest-Obs-for-all-variables/m-p/632674#M77833</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-03-17T14:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Print 20 Highest Obs for all variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Print-20-Highest-Obs-for-all-variables/m-p/632683#M77835</link>
      <description>&lt;P&gt;You can get this information from PROC UNIVARIATE. If you don't mind also getting the lowest values, use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc univariate data=Sashelp.Cars nextrobs=20;
   ods select ExtremeObs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't want the low values, write the ExtremeObs table to a data set and use PROC PRINT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
proc univariate data=Sashelp.Cars nextrobs=20;
   ods output ExtremeObs=XOBs;
run;
ods select all;

proc print data=XObs noobs;
  by VarName notsorted;
  var High HighObs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 14:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Print-20-Highest-Obs-for-all-variables/m-p/632683#M77835</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-03-17T14:45:47Z</dc:date>
    </item>
  </channel>
</rss>

