<?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: Aggregate in data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-in-data-step/m-p/885840#M350060</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
set sashelp.class;
run;

proc sort data=class;
by sex descending age;
run;

*Does not deal with ties correctly;
data oldest_by_sex;
set class;
by sex descending age;
if first.sex ;
run;

*accounts for ties;
proc sql;
create table want as 
select *
from class
group by sex
having age=max(age);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two basic solutions above, if you rephrase question to oldest of each gender so we can use sashelp.class (too lazy to make fake data). Note the different results if you use data step because ties are not accounted for...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jul 2023 15:23:41 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2023-07-21T15:23:41Z</dc:date>
    <item>
      <title>Aggregate in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-in-data-step/m-p/885790#M350039</link>
      <description>&lt;P&gt;I came across this question from someone which I'm not sure how to address it in data step.&amp;nbsp; Question is I have a dataset which has variables like - Student_Name, Subject, Marks. Now I want to identify the&lt;/P&gt;
&lt;P&gt;student name who scored high mark in each subject.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Excepted Result:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;James Maths 95&lt;/P&gt;
&lt;P&gt;David&amp;nbsp; English 98&lt;/P&gt;
&lt;P&gt;Kiran&amp;nbsp; &amp;nbsp;Social 97&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 11:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-in-data-step/m-p/885790#M350039</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-07-21T11:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-in-data-step/m-p/885791#M350040</link>
      <description>&lt;P&gt;The word "Aggregate" is used in the title, but nothing in your question is finding an aggregate (at least the way I understand the word). So, I'm confused.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, why does this have to be done in a DATA step? There are plenty of other ways to do this that are not DATA step that might be more efficient and easier to program. It is certainly my philosophy that I choose to provide answers using the tool that does the job the best, and I do not feel bound by a user who says this has to be done in a DATA step.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 11:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-in-data-step/m-p/885791#M350040</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-21T11:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-in-data-step/m-p/885792#M350041</link>
      <description>This is the interview question to my team member to test the knowledge in&lt;BR /&gt;data step.&lt;BR /&gt;&lt;BR /&gt;I said aggregate as we want to use max and group by in SQL to achieve this.&lt;BR /&gt;</description>
      <pubDate>Fri, 21 Jul 2023 11:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-in-data-step/m-p/885792#M350041</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-07-21T11:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-in-data-step/m-p/885800#M350045</link>
      <description>&lt;P&gt;But there is nothing in your question about the data that could be called "aggregate".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I implied earlier, doing this in a DATA step is probably not the best way to achieve this, there are better/easier ways, so why test the user's knowledge of doing this in a DATA step?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you mention SQL. What have you tried so far?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 12:05:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-in-data-step/m-p/885800#M350045</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-21T12:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-in-data-step/m-p/885834#M350055</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;This is the interview question to my team member to test the knowledge in&lt;BR /&gt;data step.&lt;BR /&gt;&lt;BR /&gt;I said aggregate as we want to use&lt;STRONG&gt; max and group by in SQL&lt;/STRONG&gt; to achieve this.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which is specifically stating use of something other than a data step, so still not getting what "aggregate in data step" is related.&lt;/P&gt;
&lt;P&gt;Three example values, each with a separate value for Subject and saying the requirement is to identify the Student with the highest score for each subject is a pretty lame example data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And from the extremely limited information it looks like a SORT should be involved, which is not really a data step concept.&lt;/P&gt;
&lt;P&gt;Given a realistic example of data with multiple students, multiple subjects and multiple scores here is a "data step" solution:&lt;/P&gt;
&lt;PRE&gt;Proc sort data=have;
   by subject descending score;
run;

data want;
   set have;
   by subject;
   if first.subject;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Jul 2023 14:56:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-in-data-step/m-p/885834#M350055</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-07-21T14:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-in-data-step/m-p/885840#M350060</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
set sashelp.class;
run;

proc sort data=class;
by sex descending age;
run;

*Does not deal with ties correctly;
data oldest_by_sex;
set class;
by sex descending age;
if first.sex ;
run;

*accounts for ties;
proc sql;
create table want as 
select *
from class
group by sex
having age=max(age);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two basic solutions above, if you rephrase question to oldest of each gender so we can use sashelp.class (too lazy to make fake data). Note the different results if you use data step because ties are not accounted for...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 15:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-in-data-step/m-p/885840#M350060</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-21T15:23:41Z</dc:date>
    </item>
  </channel>
</rss>

