<?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 proc means output in descending and ascending order in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/proc-means-output-in-descending-and-ascending-order/m-p/716609#M27450</link>
    <description>&lt;P&gt;I ran the following code as I want a table that shows timeperiod in descending order, and techid and female in ascending order&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means data =have n mean std&amp;nbsp; min max maxdec=2;&lt;/P&gt;
&lt;P&gt;class timeperiod techid female / descending;&lt;/P&gt;
&lt;P&gt;var var1 var2 ;&lt;/P&gt;
&lt;P&gt;types techid timeperiod*techid*female ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I got – I also tried sorting as below before the proc means but it made no difference&lt;/P&gt;
&lt;P&gt;proc sort; by timeperiod descending techid female; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help!&lt;/P&gt;
&lt;TABLE&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TD width="85"&gt;
&lt;P&gt;&lt;STRONG&gt;timeperiod&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="60"&gt;
&lt;P&gt;&lt;STRONG&gt;techid&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;&lt;STRONG&gt;female&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD rowspan="4" width="85"&gt;
&lt;P&gt;2020_P3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD rowspan="2" width="60"&gt;
&lt;P&gt;862&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="78"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="2" width="60"&gt;
&lt;P&gt;825&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="78"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="4" width="85"&gt;
&lt;P&gt;2020_P1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD rowspan="2" width="60"&gt;
&lt;P&gt;825&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="78"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="2" width="60"&gt;
&lt;P&gt;845&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="78"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="4" width="85"&gt;
&lt;P&gt;2019_P3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD rowspan="2" width="60"&gt;
&lt;P&gt;825&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="78"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="2" width="60"&gt;
&lt;P&gt;845&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="78"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
    <pubDate>Wed, 03 Feb 2021 18:59:36 GMT</pubDate>
    <dc:creator>urban58</dc:creator>
    <dc:date>2021-02-03T18:59:36Z</dc:date>
    <item>
      <title>proc means output in descending and ascending order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-means-output-in-descending-and-ascending-order/m-p/716609#M27450</link>
      <description>&lt;P&gt;I ran the following code as I want a table that shows timeperiod in descending order, and techid and female in ascending order&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means data =have n mean std&amp;nbsp; min max maxdec=2;&lt;/P&gt;
&lt;P&gt;class timeperiod techid female / descending;&lt;/P&gt;
&lt;P&gt;var var1 var2 ;&lt;/P&gt;
&lt;P&gt;types techid timeperiod*techid*female ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I got – I also tried sorting as below before the proc means but it made no difference&lt;/P&gt;
&lt;P&gt;proc sort; by timeperiod descending techid female; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help!&lt;/P&gt;
&lt;TABLE&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TD width="85"&gt;
&lt;P&gt;&lt;STRONG&gt;timeperiod&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="60"&gt;
&lt;P&gt;&lt;STRONG&gt;techid&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;&lt;STRONG&gt;female&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD rowspan="4" width="85"&gt;
&lt;P&gt;2020_P3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD rowspan="2" width="60"&gt;
&lt;P&gt;862&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="78"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="2" width="60"&gt;
&lt;P&gt;825&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="78"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="4" width="85"&gt;
&lt;P&gt;2020_P1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD rowspan="2" width="60"&gt;
&lt;P&gt;825&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="78"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="2" width="60"&gt;
&lt;P&gt;845&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="78"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="4" width="85"&gt;
&lt;P&gt;2019_P3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD rowspan="2" width="60"&gt;
&lt;P&gt;825&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="78"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="2" width="60"&gt;
&lt;P&gt;845&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="78"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="78"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 03 Feb 2021 18:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-means-output-in-descending-and-ascending-order/m-p/716609#M27450</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2021-02-03T18:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: proc means output in descending and ascending order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-means-output-in-descending-and-ascending-order/m-p/716623#M27451</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/322157"&gt;@urban58&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use two CLASS statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;class timeperiod / descending;
class techid female;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Here's a fully worked example (restricted to one statistic and one analysis variable for simplification):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do timeperiod='2019_P3', '2020_P1', '2020_P3';
  do techid=845, 825, 862;
    do female=0, 1;
      do _n_=1 to 10;
        var1=rand('uniform');
        output;
      end;
    end;
  end;
end;
run;

proc means data=have n;
class timeperiod / descending;
class techid female;
var var1;
types techid timeperiod*techid*female;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;DIV align="left"&gt;
&lt;PRE&gt; Analysis Variable : var1

                  N
      techid    Obs      N
--------------------------
         825     60     60

         845     60     60

         862     60     60
--------------------------


               Analysis Variable : var1

                                                N
timeperiod          techid          female    Obs      N
--------------------------------------------------------
2020_P3                825               0     10     10

                                         1     10     10

                       845               0     10     10

                                         1     10     10

                       862               0     10     10

                                         1     10     10

2020_P1                825               0     10     10

                                         1     10     10

                       845               0     10     10

                                         1     10     10

                       862               0     10     10

                                         1     10     10

2019_P3                825               0     10     10

                                         1     10     10

                       845               0     10     10

                                         1     10     10

                       862               0     10     10

                                         1     10     10
--------------------------------------------------------&lt;/PRE&gt;
As desired, the output&amp;nbsp;&lt;SPAN&gt;shows &lt;FONT face="courier new,courier"&gt;timeperiod&lt;/FONT&gt; in descending order, and &lt;FONT face="courier new,courier"&gt;techid&lt;/FONT&gt;&amp;nbsp;(in both tables) and &lt;FONT face="courier new,courier"&gt;female&lt;/FONT&gt; in ascending order -- regardless of the sort order in dataset HAVE (see the DO statements).&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 20:59:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-means-output-in-descending-and-ascending-order/m-p/716623#M27451</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-03T20:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: proc means output in descending and ascending order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-means-output-in-descending-and-ascending-order/m-p/716629#M27452</link>
      <description>&lt;P&gt;When you sorted the data did you use /order = data on the class statement?&lt;/P&gt;
&lt;P&gt;With proc sort you place Descending BEFORE the variable that you want sorted in descending order.&lt;/P&gt;
&lt;P&gt;So you want&lt;/P&gt;
&lt;P&gt;by descending timeperiod techid female;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may also want to change the order of the Types list. TYPES interacts with the order of the CLASS variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without actual data we can't test code.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 19:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-means-output-in-descending-and-ascending-order/m-p/716629#M27452</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-03T19:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: proc means output in descending and ascending order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-means-output-in-descending-and-ascending-order/m-p/716650#M27453</link>
      <description>Do you mean descending based on the values of the time_period or of the values that are summarized?&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Feb 2021 20:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-means-output-in-descending-and-ascending-order/m-p/716650#M27453</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-03T20:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: proc means output in descending and ascending order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-means-output-in-descending-and-ascending-order/m-p/717213#M27487</link>
      <description>&lt;P&gt;sorry for the delay in responding.&lt;/P&gt;
&lt;P&gt;Both yours and ballardw code/advice gave the same output for my data - the output was great except techid did not sort properly except for the latest timeperiod.&lt;/P&gt;
&lt;P&gt;There is something with my data which I'm trying to understand.&lt;/P&gt;
&lt;P&gt;Much thanks,&lt;/P&gt;
&lt;P&gt;Margaret&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 21:11:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-means-output-in-descending-and-ascending-order/m-p/717213#M27487</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2021-02-05T21:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: proc means output in descending and ascending order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-means-output-in-descending-and-ascending-order/m-p/717242#M27488</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/322157"&gt;@urban58&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;(...) techid did not sort properly except for the latest timeperiod.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;There is something with my data which I'm trying to understand.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One common reason for strange, unexpected sort orders are blanks or other invisible characters in character variables. Is &lt;FONT face="courier new,courier"&gt;techid&lt;/FONT&gt; a character variable (according to PROC CONTENTS output)? And, if so, what is the defined length of the variable (again: see PROC CONTENTS output)? Does &lt;FONT face="courier new,courier"&gt;techid&lt;/FONT&gt; have hundreds of different values or would it be feasible to review a PROC FREQ output showing the distinct values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does the improper sort order look like, compared to the proper sort order in the latest timeperiod? Can you show us the relevant portion of your PROC MEANS output or even a sample of your data so that we can reproduce the issue? Obviously, the analysis variables (&lt;FONT face="courier new,courier"&gt;var1&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;var2&lt;/FONT&gt;) are irrelevant and can be omitted.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 22:50:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-means-output-in-descending-and-ascending-order/m-p/717242#M27488</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-05T22:50:00Z</dc:date>
    </item>
  </channel>
</rss>

