Hi
I'm struggling to understand why date/datetime directives for picture formats don't work for me as documented (SAS 9.2 TS Level 2M3, X64_VSPRO platform).
It seems that directive %V and %W don't work at all, and that %U doesn't have a leading zero. Any ideas what's going wrong here?
That's what I find in the docu:
/**
%U
week number of the year as a decimal number (0,53) with leading 0. Sunday is considered the first day of the week.
%V
week number (01-53) with the first Monday as the start day of the first week. Minimum days of the first week is 4.
%W
week number (00-53) with the first Monday as the start day of the first week.
*/
That's the code I'm running:
proc format;
picture DTyyyyU
low-high='%Y%U' (datatype=datetime );
picture DTyyyy0U
low-high='%Y%0U' (datatype=datetime );
picture DTyyyyV
low-high='%Y%V' (datatype=datetime );
picture DTyyyy0V
low-high='%Y%0W' (datatype=datetime );
picture DTyyyyW
low-high='%Y%W' (datatype=datetime );
picture DTyyyy0W
low-high='%Y%0W' (datatype=datetime );
picture DyyyyU
low-high='%Y%U' (datatype=date );
picture Dyyyy0U
low-high='%Y%0U' (datatype=date );
picture DyyyyV
low-high='%Y%V' (datatype=date );
picture Dyyyy0V
low-high='%Y%0W' (datatype=date );
picture DyyyyW
low-high='%Y%W' (datatype=date );
picture Dyyyy0W
low-high='%Y%0W' (datatype=date );
run;
options ls=100;
data _null_;
put 10*'*' @12 'with datetime values' @33 60*'*';
do var='01jan2011 00:00:00'dt,'24apr2011 00:00:00'dt,'25apr2011 00:00:00'dt;
put '%Y%U: ' var DTyyyyU6. ' ' @;
put '%Y%0U: ' var DTyyyy0U6. ' ' @;
put '%Y%V: ' var DTyyyyV6. ' ' @;
put '%Y%0V: ' var DTyyyy0V6. ' ' @;
put '%Y%W: ' var DTyyyyW6. ' ' @;
put '%Y%0W: ' var DTyyyy0W6. ' ' ;
end;
put 10*'*' @12 'with date values' @29 64*'*';
do var='01jan2011'd,'24apr2011'd,'25apr2011'd;
put '%Y%U: ' var DyyyyU6. ' ' @;
put '%Y%0U: ' var Dyyyy0U6. ' ' @;
put '%Y%V: ' var DyyyyV6. ' ' @;
put '%Y%0V: ' var Dyyyy0V6. ' ' @;
put '%Y%W: ' var DyyyyW6. ' ' @;
put '%Y%0W: ' var Dyyyy0W6. ' ' ;
end;
put 92*'*';
run;
And that's the result I'm getting:
********** with datetime values ************************************************************
%Y%U: 20110 %Y%0U: 201100 %Y%V: 2011 %Y%0V: 2011 %Y%W: 2011 %Y%0W: 2011
%Y%U: 201117 %Y%0U: 201117 %Y%V: 2011 %Y%0V: 2011 %Y%W: 2011 %Y%0W: 2011
%Y%U: 201117 %Y%0U: 201117 %Y%V: 2011 %Y%0V: 2011 %Y%W: 2011 %Y%0W: 2011
********** with date values ****************************************************************
%Y%U: 20110 %Y%0U: 201100 %Y%V: 2011 %Y%0V: 2011 %Y%W: 2011 %Y%0W: 2011
%Y%U: 201117 %Y%0U: 201117 %Y%V: 2011 %Y%0V: 2011 %Y%W: 2011 %Y%0W: 2011
%Y%U: 201117 %Y%0U: 201117 %Y%V: 2011 %Y%0V: 2011 %Y%W: 2011 %Y%0W: 2011
********************************************************************************************
Thanks
Patrick