BookmarkSubscribeRSS Feed
Mikeyjh
Calcite | Level 5

Hi, Hope someone can help me out of the mess I'm in with Proc tabulate.

I have this statement:

proc tabulate data = dataIn;

     var catCount;

     class studyID orderBy dttm desc type;

     table studyID*type*orderBy*desc*(style=Header),

          catCount*dttm*max=' ';

run;

This works ok except I need to order the analysis variable going from left to right across the table by the datetime field dttm. How can I specify dttm to be ordered as either asc or desc?

This is what I need.

studyIDTypeOrderByDesc01/01/201402/01/201403/01/2014
xyzSubject1Screened
2Randomised
Form3SDV
4Locked
Query5Genrated
6Outstanding
3 REPLIES 3
data_null__
Jade | Level 19

you need to look a the documentation for the CLASS statment.

Base SAS(R) 9.3 Procedures Guide, Second Edition

ballardw
Super User

You can have multiple class statements so you can set class options differently for different variables. So

Class dttm / ascending; or Class dttm / descending;

If I understand your comment about the analysis variable I think you may want dttm=''*catcount=''*max='';

sgnolek
Obsidian | Level 7

There are a couple of ways that you can order data within a table, using options in the PROC TABULATE statement itself, or within a CLASS statement. I think what you will want to do is use the CLASS statement.

Within a CLASS statement you can order the data in the following ways (from the documentation):

ORDER=DATA | FORMATTED | FREQ | UNFORMATTED

                        

DATA: orders values according to their order in the input data set.                                

FORMATTED: orders values by their ascending formatted values. This order depends on your operating environment.                                                         

FREQ: orders values by descending  frequency count.                                

UNFORMATTED: orders values by their  unformatted values, which yields the same order as PROC SORT.                             

So, I bet that if you sort the data in the order you want the dttm variables to appear, and create separate CLASS statement for the dttm variable (like shown), you will get what you need.
Of course, this might mix up the order of other variables, so you might need to have separate CLASS statements for them, even using the PRELOADFMT option (which is a great feature!).

One wonderful, but simple, resource for understanding PROC TABULATE is this paper: http://www2.sas.com/proceedings/sugi30/258-30.pdf. Good luck!
proc sort data = dataln; by dttm; run;

proc tabulate data = dataIn;

     var catCount;

     class dttm / order = data;

     class studyID orderBy desc type;

     table studyID*type*orderBy*desc*(style=Header),

          catCount*dttm*max=' ';

run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1217 views
  • 0 likes
  • 4 in conversation