BookmarkSubscribeRSS Feed
hein68
Quartz | Level 8

Hello.  I wrote some proc tabulate code that is working for me with continuous outcome variables but not categorical outcome variables.  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.  I cannot drop it in, sorry.

proc tabulate data=data format=6.1 nosep order=internal;  

class group / descending;

class time;

var contvar;

table contvar*(n mean std nmiss),group*time;

run;

How would I get a table with n and % for categorical variables by group (sorted ascending) and time (pre and post) sorted descending?

Thanks!

 

3 REPLIES 3
Tom
Super User Tom
Super User

Didn't the DESCENDING keyword on the CLASS statement work?

It seems to work for me.

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;

Screenshot 2026-07-09 at 2.31.10 PM.png

ballardw
Super User

 

 


@hein68 wrote:

Hello.  I wrote some proc tabulate code that is working for me with continuous outcome variables but not categorical outcome variables.  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.  I cannot drop it in, sorry.

proc tabulate data=data format=6.1 nosep order=internal;  

class group / descending;

class time;

var contvar;

table contvar*(n mean std nmiss),group*time;

run;

How would I get a table with n and % for categorical variables by group (sorted ascending) and time (pre and post) sorted descending?

Thanks!

 


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.

 

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)  things may appear as if they are not ordered.

 

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.

Ksharp
Super User
As ballardw said, it would be better if you could post some data and the desired output report.
So we can test your code and get output .

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch Now →
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 114 views
  • 0 likes
  • 4 in conversation