DATA Step, Macro, Functions and more

Picture formats: date/datetime directives

Reply
Respected Advisor
Posts: 4,173

Picture formats: date/datetime directives

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
Respected Advisor
Posts: 3,799

Re: Picture formats: date/datetime directives

I don't think V and W directives have been implemented. Although I see them documented in my 9.2 documentation. There are formats in the NLS
[pre]weekU weekV and weekW[/pre]
that may be helpful.
Respected Advisor
Posts: 4,173

Re: Picture formats: date/datetime directives

Posted in reply to data_null__
Thanks data _null_
Really rare that the SAS docu gets it so wrong.
Super User
Posts: 10,018

Re: Picture formats: date/datetime directives

Hi.Patrick
Today I check something in SAS documentation.I found some interesting thing.
Maybe just as _null_ said, %V %W directives is only suitable for some local value and
local function.
[pre]
data temp;
date=19802; format date yymmdd10.;
a=nldate(date,'%Y%0V'); b=nldate(date,'%Y%0W');
put date= a= b=;
run;



76 data temp;
77 date=19802; format date yymmdd10.;
78 a=nldate(date,'%Y%0V'); b=nldate(date,'%Y%0W');
79 put date= a= b=;
80 run;

date=2014-03-20 a=201412 b=201411
[/pre]

Ksharp
Respected Advisor
Posts: 4,173

Re: Picture formats: date/datetime directives

Hi Ksharp
Weird!
So these directives are implemented somehow but work different than the other ones.
Good to know though.
Thanks
Patrick
Valued Guide
Posts: 2,177

Re: Picture formats: date/datetime directives

looks like a "feature" to be dealt with or removed
Ask a Question
Discussion stats
  • 5 replies
  • 186 views
  • 0 likes
  • 4 in conversation