DATA Step, Macro, Functions and more

Order by Date on Proc tabulate

Posts: 42

Order by Date on Proc tabulate


I have created a tabulate below but I need to sort the dates from earliest to latest.

Proc tabulate data J_final;
Class date;
Var move can;
Table (date=""),

My output would go in alphabetical order
Date move can
April16 4 6
April17 2 3
Aug16 6 4
Aug17 2 5

Any idea what i need to add to change it please?

Super User
Posts: 13,283

Re: Order by Date on Proc tabulate

Posted in reply to Brandon16

I have to ask because it is a frequent problem with "dates". Is your date value an actual SAS date valued variable? This means that when you run proc contents on the data set or examine the variable properties the variable is Numeric and (usually) has a date format such as DATE9. , mmddyy10 or similar assigned.


If so then you assign a format that would have the month first such as WORDDATE and on the class statement for date use the order option formatted:


class date / order=formatted;

format date worddate18. ;


Provide data if that doesn't work. Instructions here: will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.


Unless you have removed a lot of stuff from your code the () in the table statement you show aren't doing much of anything

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation