<?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: Top value in output in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567496#M11520</link>
    <description>* the desired</description>
    <pubDate>Thu, 20 Jun 2019 01:20:40 GMT</pubDate>
    <dc:creator>Kamal5522</dc:creator>
    <dc:date>2019-06-20T01:20:40Z</dc:date>
    <item>
      <title>Top value in output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567494#M11518</link>
      <description>Hi SAS Community&lt;BR /&gt;I want only top value row in output of below dataset&lt;BR /&gt;Could you please what coding would be used ?&lt;BR /&gt;Name Marks&lt;BR /&gt;Rao 50&lt;BR /&gt;Tom 60&lt;BR /&gt;Matt 90&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Output Required - Top Marks&lt;BR /&gt;Matt 90&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 20 Jun 2019 01:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567494#M11518</guid>
      <dc:creator>Kamal5522</dc:creator>
      <dc:date>2019-06-20T01:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Top value in output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567495#M11519</link>
      <description>I want to achieve thebdesired output using first. and last. concept</description>
      <pubDate>Thu, 20 Jun 2019 01:20:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567495#M11519</guid>
      <dc:creator>Kamal5522</dc:creator>
      <dc:date>2019-06-20T01:20:10Z</dc:date>
    </item>
    <item>
      <title>Re: Top value in output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567496#M11520</link>
      <description>* the desired</description>
      <pubDate>Thu, 20 Jun 2019 01:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567496#M11520</guid>
      <dc:creator>Kamal5522</dc:creator>
      <dc:date>2019-06-20T01:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Top value in output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567503#M11522</link>
      <description>&lt;P&gt;If you only want one row then these two version could be ok.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length name $ 16 marks 8;
	input Name Marks;
datalines;
Rao 50
Tom 60
Matt 90
;;;
run;

proc sql noprint;
	create table want as 
	select name, marks 
	from have
	having marks = max(marks);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=have_sorted;
	by name descending marks;
run;

data want;
	set have_sorted (obs=1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Jun 2019 01:48:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567503#M11522</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-06-20T01:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: Top value in output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567504#M11523</link>
      <description>Hi Heffo&lt;BR /&gt;Thanks for your suggestion&lt;BR /&gt;Is it possible to get the desired output by using first dot and last dot concept</description>
      <pubDate>Thu, 20 Jun 2019 01:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567504#M11523</guid>
      <dc:creator>Kamal5522</dc:creator>
      <dc:date>2019-06-20T01:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Top value in output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567506#M11524</link>
      <description>&lt;P&gt;Yes, but it makes no sense if you only want one single row.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=have_sorted;
	by name descending marks;
run;

data want;
	set have_sorted;
	by name;
	if first.name then output; *or just if first.name;;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This code will give you the top value for each person. So, it is only logical if your data set contains multiple marks for each individual.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, doing it with the first.name you read all rows of the data in the data step, so potentially a bit slower if you have a big data set. I would say that it is bad form to do it that way, unless you have a specific reason to do it. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jun 2019 21:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567506#M11524</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-06-23T21:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: Top value in output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567847#M11581</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277241"&gt;@Kamal5522&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Within the context of your problem, using FIRST.x/LAST.x makes sense only if you want it as a method of resolving ties - in case different persons have the same highest mark. However, doing so requires to sort the file, which makes no sense for a linear, single-pass problem. Instead, it can be done simply by:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop = _:) ;                           
  do until (z) ;                                  
    set have (rename=(name=_n marks=_m)) end = z ;
    if _m LE marks then continue ;                
    name  = _n ;                                  
    marks = _m ;                                  
  end ;                                           
run ;                                             
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the case there are ties by MARKS, it will choose the first physical record with the highest mark. If you want the last instead, use LT instead of LE in the IF statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that using SQL for this type of problem wastes computer resources, as it has to remerge the aggregate with the original data and hence needs two passes through the input data set. As a result, it runs 5 times slower than the DATA step above and consumes twice the memory.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 07:06:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Top-value-in-output/m-p/567847#M11581</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-06-21T07:06:04Z</dc:date>
    </item>
  </channel>
</rss>

