sorry this seems a bit late but no-one seems to have thought of a natural solution.
> I have some data that I've summarized by month for
> the first six months and then by week for the seventh
> month. The reworked the file and the date values now
> reside in one column as sas dates. I want to display
> the month values with an monyy7. format and the week
> values with a date7. format
An attractive feature of the SAS language is user-defineable formatting.
This allows you to choose the format for a range of values (not just the formattted value).
So, for recent events you can summarise (or tabulate) in detail, while providing a broad interval for older events.
An important benefit in SAS is the easy facility to establish interval dates.
Today is provided by function today() or date()
The beginning of last week is intnx( 'week', today(), -1 )
The beginning of last month is intnx( 'month', today(), -1 )
These examples have been written for the data step environment. As parameters the syntax is slightly different. A date constant for today is '07Apr2010'd. This style can be generated by the SAS Macro Language with syntax like[pre] %let today = %sysfunc( today(), date9 ) ;[/pre] That %sysfunc() wrapper supports almost all stand-alone data step functions (and none that depend on the data step environment like lag() and vlabel() ). The second parameter in that %sysfunc() call i.e. date9 is the format I use to convert the numeric result of the function call which is the first parameter of %sysfunc() into text (for the "string-only"macro environment)
So, date parameters can be calculated ready to use when choosing the varieties of date formatting you want.
first 6 months by month, thereafter by week [pre] %let ref1date = 31dec2008 ; **** just for testing ;
%let ref2date = %sysfunc( intnx( month, "&ref1date"d, 6, sameday ), date9 ) ;
proc format cntlout= specdat_cntl ;
value specDat low - "&ref1date"d = [year4.]
"&ref1date"d - "&ref2date"d = [monYY7.]
"&ref2date"d - high = [date7.]
;
run ;[/pre]* even though present in more than one date range the "&ref1date"d and "&ref2date"d will not overlap. By default the upper bound is included and the lower bound is excluded, when format ranges finish and start on the same number. Check out the cntlout= dataset specDat_cntl columns sexcl (start exclude) eexcl (end exclude) ;
Then just add a statement to Bill's proc tabulate to associate specDat. format with the variable Period as below.
proc tabulate data=SlitLoss4;
class Op_No Grd_Cd Period;
format period specDat. ;
var EdgeWtLoss;
table (Op_No=' ' all) *
(Period='Month / Week Of' all),
(Grd_Cd='Grade' all) *
EdgeWtLoss=' Weight Loss ' * sum=''
;
hope it proves useful
PeterC