- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 04-23-2011 10:45 PM
(1567 views)
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
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
5 REPLIES 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
[pre]weekU weekV and weekW[/pre]
that may be helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks data _null_
Really rare that the SAS docu gets it so wrong.
Really rare that the SAS docu gets it so wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ksharp
Weird!
So these directives are implemented somehow but work different than the other ones.
Good to know though.
Thanks
Patrick
Weird!
So these directives are implemented somehow but work different than the other ones.
Good to know though.
Thanks
Patrick
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
looks like a "feature" to be dealt with or removed