<?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: Select observations that meet a criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187388#M304016</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The issue although it may also be the desired result as it was not specified, is that if you have 2 distinct PI_NO with the same x=max(x) value, you will output both with that proc sql approach.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Similarly, depending on the size of your data, using proc summary instead of a data step or sql solution could take far more time than it should.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Again, depending on the size of your data and whether it is already pre-sorted by HH_NO or not, there are hash solutions, by group processing with point= solution and others that could get you faster processing and solve the proc sql potential duplicate HH_NO issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So anyway if the solutions above run too slow or don't fully comply with your requirement, I will gladly provide either a hash or by processing solution but just in case you did not have such a huge dataset and either the above worked, I'll wait for a reply to provide an alternative solution.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 03 Jan 2014 14:13:02 GMT</pubDate>
    <dc:creator>Vince28_Statcan</dc:creator>
    <dc:date>2014-01-03T14:13:02Z</dc:date>
    <item>
      <title>Select observations that meet a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187385#M304013</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;HH_No&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;PI_No&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;X&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;01&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;01&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;01&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;02&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;02&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;01&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;03&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;01&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With a dataset similar (but with many more rows) to the above, I want to select &lt;/P&gt;&lt;P&gt;for each HH_No&lt;/P&gt;&lt;P&gt;the PI_No&amp;nbsp; with the highest X.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The output should show the HH_No, PI_No with the highest X &amp;amp; the corresponding X.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jan 2014 09:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187385#M304013</guid>
      <dc:creator>apple</dc:creator>
      <dc:date>2014-01-03T09:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Select observations that meet a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187386#M304014</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input HH_No PI_No X;&lt;/P&gt;&lt;P&gt;format HH_No PI_No z2.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;01 01 1&lt;/P&gt;&lt;P&gt;01 02 5&lt;/P&gt;&lt;P&gt;02 01 2&lt;/P&gt;&lt;P&gt;03 01 3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc summary data=have nway;&lt;/P&gt;&lt;P&gt;class HH_No;&lt;/P&gt;&lt;P&gt;output out=want (drop=_:) maxid(X(PI_No X))=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jan 2014 10:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187386#M304014</guid>
      <dc:creator>Keith</dc:creator>
      <dc:date>2014-01-03T10:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Select observations that meet a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187387#M304015</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: Consolas;"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: Consolas;"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: Consolas;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: Consolas;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: Consolas;"&gt; * &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: Consolas;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: Consolas;"&gt; have &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: Consolas;"&gt;group&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: Consolas;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: Consolas;"&gt; HH_No&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: Consolas;"&gt;having&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: Consolas;"&gt; x=max(x);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: Consolas;"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: Consolas;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jan 2014 13:42:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187387#M304015</guid>
      <dc:creator>pradeepalankar</dc:creator>
      <dc:date>2014-01-03T13:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Select observations that meet a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187388#M304016</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The issue although it may also be the desired result as it was not specified, is that if you have 2 distinct PI_NO with the same x=max(x) value, you will output both with that proc sql approach.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Similarly, depending on the size of your data, using proc summary instead of a data step or sql solution could take far more time than it should.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Again, depending on the size of your data and whether it is already pre-sorted by HH_NO or not, there are hash solutions, by group processing with point= solution and others that could get you faster processing and solve the proc sql potential duplicate HH_NO issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So anyway if the solutions above run too slow or don't fully comply with your requirement, I will gladly provide either a hash or by processing solution but just in case you did not have such a huge dataset and either the above worked, I'll wait for a reply to provide an alternative solution.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jan 2014 14:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187388#M304016</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2014-01-03T14:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Select observations that meet a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187389#M304017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply. But I don't understand this line:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;output out=want (drop=_:) maxid(X(PI_No X))=;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Specifically, I don't understand&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;_:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(X(PI_No X))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why is it blank after the = in "maxid(X(PI_No X))=;"?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Jan 2014 08:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187389#M304017</guid>
      <dc:creator>apple</dc:creator>
      <dc:date>2014-01-04T08:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Select observations that meet a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187390#M304018</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for explaining things. I am new to SAS and will like to know what is "a hash or by processing solution".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Jan 2014 08:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187390#M304018</guid>
      <dc:creator>apple</dc:creator>
      <dc:date>2014-01-04T08:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: Select observations that meet a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187391#M304019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A BY processing solution is a datastep where you take advantage of SAS automatic variables that signal the first and last observations of each &lt;EM&gt;BY group&lt;/EM&gt;. It is very efficient but requires the input dataset to be sorted by the &lt;EM&gt;BY variables&lt;/EM&gt;. For your simple task, it would look like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data have;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;input HH_No PI_No X;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;format HH_No PI_No z2.;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;01 01 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;01 02 5&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;02 01 2&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;03 01 3&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sort data=have; by HH_No X; run; &lt;/STRONG&gt;/* not required if dataset is already sorted */&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data want;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;set have; by HH_No;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;if last.HH_No; &lt;/STRONG&gt;/* keep last observation of each BY group */&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc print data=want noobs; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Jan 2014 03:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187391#M304019</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-01-05T03:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: Select observations that meet a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187392#M304020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;'maxid(X( PI_No X )) =' says to return PI_No and X for the highest value of X per group.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;The = sign afterwards just enables new variable names to be created if desired, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;e.g. &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;maxid(X( PI_No X ))&lt;/SPAN&gt; = newvar1 newvar2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Leaving it blank retains the existing variables names (PI_No X)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jan 2014 16:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187392#M304020</guid>
      <dc:creator>Keith</dc:creator>
      <dc:date>2014-01-06T16:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Select observations that meet a criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187393#M304021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As PG has examplified by-group processing, I will only answer the hash portion.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SAS Hash Object is a fairly recent feature. It is essentially a "lookup table" that is usable through the data step. The strength of Hashing for the specific question you've asked is that if your data wasn't already sorted according to your by-group, then a hash solution alleviates the need to pre-sort (which often is the lenghtiest part of a simple by-group process). However, the hash object is fully held in memory throughout the data step so if you have a very, very large volume of data, it is possible to face an "out of memory" error with hash solutions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Syntaxically, it also looks confusing at first glance but one gets familiar with the programing syntax quite fast. Since you mentioned you were fairly new to SAS, it is probably best to get accustomed at least to by-group processing before looking at hashing. Hashing can achieve far more than just this but since it is memory-limited, it is wiser to learn the processing tools that should work "all around". So I will refrain from providing a hash solution. There are plenty of similar examples around these forums anyway and in various SGF papers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As to add one element to Keith's description above, procedures have various built-in output. Unless tasked otherwise, the output statement in proc summary outputs outputs many more statistics than just maximum. Using output statement options allows you to control that default behaviour. See proc summary -&amp;gt; output statement documentation (it will actually point you towards proc means' output statement as they have the same options). You will find the specific explanation for the MAXID option there and how it applies the max on X, by class HH_NO but will actually output PI_No and X as the identifier for that maximum point found.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vincent&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jan 2014 17:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-observations-that-meet-a-criteria/m-p/187393#M304021</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2014-01-06T17:32:01Z</dc:date>
    </item>
  </channel>
</rss>

