<?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: Sorting, subsetting in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sorting-subsetting/m-p/299732#M63253</link>
    <description>&lt;P&gt;In addition to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom﻿&lt;/a&gt;&amp;nbsp;solution, if you want control over the levels look at TYPEs and WAYS statements in PROC MEANS.&lt;/P&gt;
&lt;P&gt;They allow you to control the different combinations of class variables, super useful and under utilized.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 21 Sep 2016 03:05:51 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-09-21T03:05:51Z</dc:date>
    <item>
      <title>Sorting, subsetting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-subsetting/m-p/299725#M63249</link>
      <description>&lt;P&gt;So, probably a simple question.&amp;nbsp; I need to find the mean of a subset of a subset of a variable (3 variables total).&amp;nbsp;&amp;nbsp;&amp;nbsp;So lets say I am trying to find the mean of NFC team scores, first by division, and then by team in the division.&amp;nbsp; I have a scores variable, a variable, division,&amp;nbsp;that includes NFC EAST, NFC WEST, NFC SOUTH, and NFC NORTH.&amp;nbsp; Then a third variable, team, &amp;nbsp;that contains all&amp;nbsp;of the teams in the conference.&amp;nbsp; I can get the mean&amp;nbsp;of the scores of the division, but when I try to go to that deeper level of teams in the division, i cannot do it.&amp;nbsp; Here is the code I would use to get the mean by division:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data = football;&lt;/P&gt;&lt;P&gt;by division;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc means data = football;&lt;/P&gt;&lt;P&gt;var scores;&lt;/P&gt;&lt;P&gt;by division;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this works just fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when I try to go by team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it gives me an error because I haven't sorted by team, which then messes up the sort my division.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any suggestions?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 01:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-subsetting/m-p/299725#M63249</guid>
      <dc:creator>BoboTheFool</dc:creator>
      <dc:date>2016-09-21T01:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting, subsetting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-subsetting/m-p/299727#M63251</link>
      <description>&lt;P&gt;Do you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = football;
by division team;
run;
 
proc means data = football;
var scores;
by division team;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 02:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-subsetting/m-p/299727#M63251</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-09-21T02:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting, subsetting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-subsetting/m-p/299729#M63252</link>
      <description>&lt;P&gt;Use the CLASS statement instead of the BY statement and you can get summary for any of the combinations you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=football ;
   class division team ;
   var score ;
   output out=want mean=mean_score ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will get overall mean, mean for each level of division, mean for each level of team and also mean of each team within division.&lt;/P&gt;
&lt;P&gt;The _TYPE_ variable will tell you which of the class variables are contributing to the result record.&lt;/P&gt;
&lt;P&gt;_TYPE_=0 &amp;nbsp;will be the overall mean.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_TYPE_=1 will be the TEAM means.&lt;/P&gt;
&lt;P&gt;_TYPE_=2 will be the DIVISION means.&lt;/P&gt;
&lt;P&gt;_TYPE_=3 will the the TEAM within DIVISION means (which for NFL teams will be the same as TEAM means since each team is in one and only one DIVISION).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 02:57:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-subsetting/m-p/299729#M63252</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-09-21T02:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting, subsetting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-subsetting/m-p/299732#M63253</link>
      <description>&lt;P&gt;In addition to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom﻿&lt;/a&gt;&amp;nbsp;solution, if you want control over the levels look at TYPEs and WAYS statements in PROC MEANS.&lt;/P&gt;
&lt;P&gt;They allow you to control the different combinations of class variables, super useful and under utilized.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 03:05:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-subsetting/m-p/299732#M63253</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-21T03:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting, subsetting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-subsetting/m-p/299736#M63254</link>
      <description>&lt;P&gt;Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the class statement was dead on.&amp;nbsp; I racked my brain for a few hours trying to figure out how to code the problem correctly.&amp;nbsp; Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Adam&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 03:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-subsetting/m-p/299736#M63254</guid>
      <dc:creator>BoboTheFool</dc:creator>
      <dc:date>2016-09-21T03:27:30Z</dc:date>
    </item>
  </channel>
</rss>

