<?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: proc tabulate with 2 nested variables for columns, 1 sorted ascending and 1 sorted descending in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-2-nested-variables-for-columns-1-sorted/m-p/990632#M380300</link>
    <description>&lt;P&gt;Didn't the DESCENDING keyword on the CLASS statement work?&lt;/P&gt;
&lt;P&gt;It seems to work for me.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do id=1 to 2;
    do group=1 to 3;
      do time=1 to 2;
        row+1;
        contvar=rand('integer',1000);
        output;
      end;
    end;
  end;
run;


proc tabulate data=have format=6.1 nosep ;  
  class group ;
  class time / descending;
  var contvar;
  table contvar*(n mean std nmiss),group*time;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2026-07-09 at 2.31.10 PM.png" style="width: 694px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/116299iBEACB18CFA901A17/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2026-07-09 at 2.31.10 PM.png" alt="Screenshot 2026-07-09 at 2.31.10 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jul 2026 18:34:08 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2026-07-09T18:34:08Z</dc:date>
    <item>
      <title>proc tabulate with 2 nested variables for columns, 1 sorted ascending and 1 sorted descending</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-2-nested-variables-for-columns-1-sorted/m-p/990620#M380299</link>
      <description>&lt;P&gt;Hello.&amp;nbsp; I wrote some proc tabulate code that is working for me with continuous outcome variables but not categorical outcome variables.&amp;nbsp; I would appreciate any help you can provide. The data is a long file where all IDs have a pre record and some IDs have a post record. Here is the code.&amp;nbsp; I cannot drop it in, sorry.&lt;/P&gt;
&lt;P&gt;proc tabulate data=data format=6.1 nosep order=internal;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;class group / descending;&lt;/P&gt;
&lt;P&gt;class time;&lt;/P&gt;
&lt;P&gt;var contvar;&lt;/P&gt;
&lt;P&gt;table contvar*(n mean std nmiss),group*time;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;How would I get a table with n and % for categorical variables by group (sorted ascending) and time (pre and post) sorted descending?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jul 2026 16:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-2-nested-variables-for-columns-1-sorted/m-p/990620#M380299</guid>
      <dc:creator>hein68</dc:creator>
      <dc:date>2026-07-09T16:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with 2 nested variables for columns, 1 sorted ascending and 1 sorted descending</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-2-nested-variables-for-columns-1-sorted/m-p/990632#M380300</link>
      <description>&lt;P&gt;Didn't the DESCENDING keyword on the CLASS statement work?&lt;/P&gt;
&lt;P&gt;It seems to work for me.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do id=1 to 2;
    do group=1 to 3;
      do time=1 to 2;
        row+1;
        contvar=rand('integer',1000);
        output;
      end;
    end;
  end;
run;


proc tabulate data=have format=6.1 nosep ;  
  class group ;
  class time / descending;
  var contvar;
  table contvar*(n mean std nmiss),group*time;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2026-07-09 at 2.31.10 PM.png" style="width: 694px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/116299iBEACB18CFA901A17/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2026-07-09 at 2.31.10 PM.png" alt="Screenshot 2026-07-09 at 2.31.10 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jul 2026 18:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-2-nested-variables-for-columns-1-sorted/m-p/990632#M380300</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-07-09T18:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with 2 nested variables for columns, 1 sorted ascending and 1 sorted descending</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-2-nested-variables-for-columns-1-sorted/m-p/990645#M380301</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/74483"&gt;@hein68&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello.&amp;nbsp; I wrote some proc tabulate code that is working for me with continuous outcome variables but not categorical outcome variables.&amp;nbsp; I would appreciate any help you can provide. The data is a long file where all IDs have a pre record and some IDs have a post record. Here is the code.&amp;nbsp; I cannot drop it in, sorry.&lt;/P&gt;
&lt;P&gt;proc tabulate data=data format=6.1 nosep order=internal;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;class group / descending;&lt;/P&gt;
&lt;P&gt;class time;&lt;/P&gt;
&lt;P&gt;var contvar;&lt;/P&gt;
&lt;P&gt;table contvar*(n mean std nmiss),group*time;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;How would I get a table with n and % for categorical variables by group (sorted ascending) and time (pre and post) sorted descending?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since your Proc Tabulate code does not use any variable called ID why do you include " where all IDs have a pre record and some IDs have a post record. " That bit of trivia apparently has no obvious connection to this problem. If you are discussing the role of a variable then name the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want Group to be ascending then why did you have the option /descending for the Group variable? The default for class variables is "ascending" but if you have a FORMAT applied to the variable(s)&amp;nbsp; things may appear as if they are not ordered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Strong hint: provide some example data in the form of a working data step and if your actual data has custom formats applied then the definitions of the formats, or at least enough to work with the example data.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jul 2026 22:30:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-2-nested-variables-for-columns-1-sorted/m-p/990645#M380301</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2026-07-09T22:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with 2 nested variables for columns, 1 sorted ascending and 1 sorted descending</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-2-nested-variables-for-columns-1-sorted/m-p/990647#M380302</link>
      <description>As ballardw said, it would be better if you could post some data and the desired output report.&lt;BR /&gt;So we can test your code and get output .</description>
      <pubDate>Fri, 10 Jul 2026 08:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-2-nested-variables-for-columns-1-sorted/m-p/990647#M380302</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-07-10T08:34:08Z</dc:date>
    </item>
  </channel>
</rss>

