Yet another way of performing a sort by formatted values, would be:
* create format;
set INDATA (rename=(YEAR=START));
keep FMTNAME TYPE HLO START END LABEL;
retain FMTNAME 'YR'
LABEL=put(input(START,??best.),best.); * convert value to numeric;
proc format cntlin=_FORMAT;
* fomatted sort;
create table OUTDATA as
select * from INDATA order by put(YEAR,$YR.);
With this any non pure digit value of YEAR will be sorted as the lowest value (hence "pre 1995").
'guess a choice of preferred method depends on more than we know. I have often had to group information into non-equal time bands (like pre1995, 1995-2000, 2001,2002,2003, ... lastyear, months of this year).
With that requirement, I found date-type class variables in the reporting procedures needed no alteration, just to be formatted with a simple user format, like:[pre]
proc format ;
low - '31dec1994'd = 'pre- 1995'
'1jan1995'd - '31dec2000'd = '1995-2000'
'1jan2001'd - "%sysfunc( intnx( year, "&sysdate"d, -1,e ), date9)"d =[year4.]
"%sysfunc( intnx( year, "&sysdate"d, 0,b ), date9)"d - high = [monyy7.]
run ;[/pre]Then given a sas data set with tran_date, I can get stats in this collection of un-equal time bands with something like[pre]proc tabulate data= my_tran_data missing ;
class tran_date ;
format tran_date clDate. ;
var purchase sale actual forecast ;
table ( tran_date all), (purchase sale actual forecast)
*sum=' '*f= comma11./ rts=15 ;
use variables that are more relevant to you