Help using Base SAS procedures

Proc tabulate

Reply
Contributor
Posts: 28

Proc tabulate

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
Respected Advisor
Posts: 3,777

Re: Proc tabulate

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

Base SAS(R) 9.3 Procedures Guide, Second Edition

Super User
Posts: 10,552

Re: Proc tabulate

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='';

Occasional Contributor
Posts: 13

Re: Proc tabulate

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;

Ask a Question
Discussion stats
  • 3 replies
  • 304 views
  • 0 likes
  • 4 in conversation