<?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: SAS Macro for top 10 and last 10 values for variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/298584#M62813</link>
    <description>&lt;PRE&gt;
As Reeza pointed out. Will you pay me some money ?


%macro top_end(data=sashelp.air , var=date,n=10,percent=);
%if %length(&amp;amp;percent) %then %do;
 %let dsid=%sysfunc(open(&amp;amp;data));
 %let nobs=%sysfunc(attrn(&amp;amp;dsid,nlobs));
 %let dsid=%sysfunc(close(&amp;amp;dsid));
 %let n=%sysevalf(&amp;amp;nobs*&amp;amp;percent,i);
%end;
data want;
 set &amp;amp;data(keep=&amp;amp;var) nobs=nobs;
 if _n_ le &amp;amp;n or 
    _n_ ge nobs-&amp;amp;n+1 ;
run;
proc print noobs;run;
%mend;

%top_end()
%top_end(percent=0.1)

&lt;/PRE&gt;</description>
    <pubDate>Thu, 15 Sep 2016 09:36:38 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-09-15T09:36:38Z</dc:date>
    <item>
      <title>SAS Macro for top 10 and last 10 values for variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/293270#M60984</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I require a sas macro for returning:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;top 10 and last 10 values of a numeric variable (Assume variable is not sorted).&lt;/LI&gt;&lt;LI&gt;alphabetically top 10 and last 10 values of a character variable&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 21:40:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/293270#M60984</guid>
      <dc:creator>deepankeranand</dc:creator>
      <dc:date>2016-08-22T21:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro for top 10 and last 10 values for variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/293271#M60985</link>
      <description>&lt;P&gt;Why a macro?&lt;/P&gt;
&lt;P&gt;What have you tried so far?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 21:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/293271#M60985</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-22T21:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro for top 10 and last 10 values for variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/293278#M60992</link>
      <description>&lt;P&gt;What do you return if there are fewer than total observations?&lt;/P&gt;
&lt;P&gt;Do missing or blank values get included?&lt;/P&gt;
&lt;P&gt;Can the top 10 and bottom 10 overlap (fewer than 20 observations);&lt;/P&gt;
&lt;P&gt;Define "top": largest (problematic for character) most frequent, alphabetic order(probematical for numeric).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 22:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/293278#M60992</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-22T22:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro for top 10 and last 10 values for variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/293313#M61008</link>
      <description>&lt;PRE&gt;
%macro top_end(data=sashelp.cars , var=make);
data want;
 set &amp;amp;data(keep=&amp;amp;var) nobs=nobs;
 if _n_ le 10 or 
    _n_ =nobs-9 or 
    _n_ =nobs-8 or
    _n_ =nobs-7 or
    _n_ =nobs-6 or
    _n_ =nobs-5 or
    _n_ =nobs-4 or
    _n_ =nobs-3 or
    _n_ =nobs-2 or
    _n_ =nobs-1 or
    _n_ =nobs ;
run;
proc print noobs;run;
%mend;

%top_end()
&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Aug 2016 03:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/293313#M61008</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-23T03:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro for top 10 and last 10 values for variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/298505#M62790</link>
      <description>&lt;P&gt;Hi Xia,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your macro gives us top 10 and bottom 10 values of a variable. Just three more enhancements:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Please can you add another option in the macro to make the n top and bottom values needed. for eg: for n=20, n=5, n=15, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. If there are missing values, delete the missing values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Add the n% percentage option, for eg: pick top 10% and bottom 10% of values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 05:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/298505#M62790</guid>
      <dc:creator>deepankeranand</dc:creator>
      <dc:date>2016-09-15T05:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro for top 10 and last 10 values for variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/298507#M62792</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76520"&gt;@deepankeranand&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Xia,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your macro gives us top 10 and bottom 10 values of a variable. Just three more enhancements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Please can you add another option in the macro to make the n top and bottom values needed. for eg: for n=20, n=5, n=15, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. If there are missing values, delete the missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Add the n% percentage option, for eg: pick top 10% and bottom 10% of values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please try something, post what you've tried and what isn't working.&lt;/P&gt;
&lt;P&gt;As phrased this isn't a request for help its a 'do my work'. If you need this type of service consider hiring a consultant.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 05:17:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/298507#M62792</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-15T05:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro for top 10 and last 10 values for variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/298584#M62813</link>
      <description>&lt;PRE&gt;
As Reeza pointed out. Will you pay me some money ?


%macro top_end(data=sashelp.air , var=date,n=10,percent=);
%if %length(&amp;amp;percent) %then %do;
 %let dsid=%sysfunc(open(&amp;amp;data));
 %let nobs=%sysfunc(attrn(&amp;amp;dsid,nlobs));
 %let dsid=%sysfunc(close(&amp;amp;dsid));
 %let n=%sysevalf(&amp;amp;nobs*&amp;amp;percent,i);
%end;
data want;
 set &amp;amp;data(keep=&amp;amp;var) nobs=nobs;
 if _n_ le &amp;amp;n or 
    _n_ ge nobs-&amp;amp;n+1 ;
run;
proc print noobs;run;
%mend;

%top_end()
%top_end(percent=0.1)

&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Sep 2016 09:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-for-top-10-and-last-10-values-for-variable/m-p/298584#M62813</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-15T09:36:38Z</dc:date>
    </item>
  </channel>
</rss>

