<?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 Need max value for each group by column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946820#M370752</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have below data set (have) and need output like below(need) :&lt;/P&gt;&lt;P&gt;TIA&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA HAVE;&lt;BR /&gt;INPUT ID PRICE YEARMONTH;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 23 2312&lt;BR /&gt;1 24 2401&lt;BR /&gt;1 25 2402&lt;BR /&gt;1 36 2403&lt;BR /&gt;2 45 2312&lt;BR /&gt;2 34 2401&lt;BR /&gt;2 53 2402&lt;BR /&gt;2 23 2403&lt;BR /&gt;2 664 2404&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA need;&lt;BR /&gt;INPUT ID PRICE YEARMONTH;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 36 2403&lt;BR /&gt;2 664 2404&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
SELECT * FROM HAVE 
GROUP BY ID ,YEARMONTH
HAVING MAX(YEARMONTH) ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Oct 2024 17:26:25 GMT</pubDate>
    <dc:creator>kajal_30</dc:creator>
    <dc:date>2024-10-09T17:26:25Z</dc:date>
    <item>
      <title>Need max value for each group by column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946820#M370752</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have below data set (have) and need output like below(need) :&lt;/P&gt;&lt;P&gt;TIA&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA HAVE;&lt;BR /&gt;INPUT ID PRICE YEARMONTH;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 23 2312&lt;BR /&gt;1 24 2401&lt;BR /&gt;1 25 2402&lt;BR /&gt;1 36 2403&lt;BR /&gt;2 45 2312&lt;BR /&gt;2 34 2401&lt;BR /&gt;2 53 2402&lt;BR /&gt;2 23 2403&lt;BR /&gt;2 664 2404&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA need;&lt;BR /&gt;INPUT ID PRICE YEARMONTH;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 36 2403&lt;BR /&gt;2 664 2404&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
SELECT * FROM HAVE 
GROUP BY ID ,YEARMONTH
HAVING MAX(YEARMONTH) ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2024 17:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946820#M370752</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2024-10-09T17:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: Need max value for each group by column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946821#M370753</link>
      <description>&lt;P&gt;PROC SUMMARY is the tool you want to use, not PROC SQL. See &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 7&lt;/A&gt; and Maxim 14 and Maxim 10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
    class id;
    var price;
    output out=want max= maxid(price(yearmonth))=yearmonth;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a general piece of advice, you want to compute statistics in the proper PROC, in this case PROC SUMMARY but in other cases PROC FREQ. Using these PROCs will provide you with better and more powerful tools (that take less time to program and less time to execute) than PROC SQL. This is particularly useful if you have lots of variables, or lots of slices (here the only slice is by ID). The idea of doing your statistics in PROC SQL is an idea which you should avoid. For small problems like this, probably there is not really a noticeable difference between PROC SQL and PROC SUMMARY, but for larger real world problems, the difference can be dramatic (in favor of PROC SUMMARY or PROC FREQ).&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2024 17:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946821#M370753</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-09T17:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need max value for each group by column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946824#M370755</link>
      <description>&lt;P&gt;can I please get in terms of proc sql as I have many more columns to add along with the join .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;kajal&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2024 18:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946824#M370755</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2024-10-09T18:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need max value for each group by column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946825#M370756</link>
      <description>&lt;P&gt;Many more columns is a situation that is handled much easier in PROC SUMMARY&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2024 18:04:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946825#M370756</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-09T18:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Need max value for each group by column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946826#M370757</link>
      <description>&lt;P&gt;To demonstrate a bit more complex example of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s advice please run the following code. You should have the SASHELP.CLASS data set provided by SAS for training and practice.&lt;/P&gt;
&lt;PRE&gt;Proc summary data=sashelp.class;
    class sex age;
    var height weight;
    output out=work.class_summary min= max= mean= std= /autoname;
run;&lt;/PRE&gt;
&lt;P&gt;The output data set contains multiple summaries of the variables height and weight with the requested statistics for height and weight. Note the _type_ variable provides information about combinations of the class variables. So we get a summary overall ( type=0), by age only (type=1), by sex only (type=2) and Sex crossed with age categories (type=3 ).&lt;/P&gt;
&lt;P&gt;To get this in Proc SQL you would have to write 4 separate Proc SQL selects with different group by . Also the handy option AUTONAME, which appends the statistic to the variable name, means you don't have to expressly provide a written out name for each stat replacing multiple&lt;/P&gt;
&lt;P&gt;mean(var) as var_mean&lt;/P&gt;
&lt;P&gt;, max(var) as var_max&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One project I have requires reporting on pretty much every crossing or single level of 7 different class variables plus the overall stats for 30 or so report variables. ONE call to proc summary creates all of the values in one data set. Select based on the value of _TYPE_ for specific report tables. About 2 pages (without the comments) of code generates about 4,000 pages of documents for the user to reference as needed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2024 18:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946826#M370757</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-10-09T18:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: Need max value for each group by column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946827#M370758</link>
      <description>&lt;P&gt;I also need to do a join so I am not able to use the join with the proc that's why It will easier for me to use Proc sql&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2024 18:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946827#M370758</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2024-10-09T18:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: Need max value for each group by column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946828#M370759</link>
      <description>&lt;P&gt;You can&amp;nbsp; run a join on the output of PROC SUMMARY&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2024 18:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-max-value-for-each-group-by-column/m-p/946828#M370759</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-09T18:30:59Z</dc:date>
    </item>
  </channel>
</rss>

