Ksharp
thank you
your experience and the posting from ArtC have sent me back to reviewing and improve my "format hunter"
Not yet a macro,( I modify the basic data step each time I'm hunting), the hunter now tries twice and reveals more that one result (at last)[pre]%let required = 23/12 ;
%let have_ = 23Dec2010;
data date_format_hunter_found( keep= fmtname str );
set sashelp.vformat ;
where fmttype='F' ; *just formats;
where also fmtname ne:'$' ; * and not character formats;
retain width %sysfunc( length( %superq(required)) ) ;
str = putn( "&have_"d, fmtname ) ; *default format width ;
if left(str) NE "&required"
and not _error_
and minw LE width LE maxw
then
str = putn( "&have_"d, fmtname, width );
* using requested width ;
if _error_ then put 'NOTE- ' fmtname= ;
_error_=0 ;
if left(str) NE "&required" then delete ;
* report on successes ;
put "&have_ &required " fmtname= str= width= ;
run;[/pre]This version finds formats for dd/mm as follows[pre]23Dec2010 23/12 fmtname=CATDFDD str=23/12 width=5
23Dec2010 23/12 fmtname=CSYDFDD str=23/12 width=5
23Dec2010 23/12 fmtname=DDMMYY str=23/12 width=5
23Dec2010 23/12 fmtname=DDMMYYS str=23/12 width=5
23Dec2010 23/12 fmtname=FRADFDD str=23/12 width=5
NOTE: Argument 2 to function PUTN at line 1256 column 9 is invalid.
fmtname=FREE
23Dec2010 23/12 fmtname=FRSDFDD str=23/12 width=5
23Dec2010 23/12 fmtname=ITADFDD str=23/12 width=5
23Dec2010 23/12 fmtname=PTGDFDD str=23/12 width=5
NOTE: There were 589 observations read [/pre]
For dd-mm layout formats found were[pre]23Dec2010 23-12 fmtname=DDMMYYD str=23-12 width=5
NOTE: Argument 2 to function PUTN at line 1281 column 9 is invalid.
fmtname=FREE
23Dec2010 23-12 fmtname=NLDDFDD str=23-12 width=5
23Dec2010 23-12 fmtname=POLDFDD str=23-12 width=5[/pre] and for mm-dd only one format was revealed[pre]23Dec2010 12-23 fmtname=MMDDYYD str=12-23 width=5[/pre]
Of course, you might prefer to create your own format with PROC FORMAT and the PICTURE statement "directives" documented at
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a002473467.htm#a000530223 and since the online-doc examples of the PICTURE statement don't demonstrate these date directives, here is one:
proc format ;
picture ksharp_date other = '%d-%m'( datatype= date ) ;
run;
%put demo %sysfunc( today(), ksharp_date. ) ;
which produced the "demo"[pre]1325 %put demo %sysfunc( today(), ksharp_date. ) ;
demo 13-11[/pre]