Takes a value containing a date in one pattern and returns that value converted to a date in another pattern.
REPATTERN (d, p, q, w)
d is a string expression representing a date. The length of d must be at least as long as the length of the source pattern specified by q. If d is larger, any excess characters must be formed by leading blanks.
The value for d must have a computational type and should have a character type. If not, the REPATTERN function converts d to character.
p is a supported date/time pattern used as the target.
q is a supported date/time pattern used as the source.
w specifies an expression (such as 1976) that can be converted to an integer.
The following are some examples of how to use REPATTERN to convert between 2-digit-year and 4-digit-year date patterns. You can use REPATTERN to convert a date from any supported pattern to any other supported pattern even if the patterns do not use the same number of digits to hold the year value.
repat: proc options(main); dcl str char(16)var; on error begin; put skip list ('Error raised. Outside century window.'); STOP: end; str = REPATTERN('770101','YYYYMMDD','YYMMDD', 1976); put skip list (str); str = REPATTERN('280101','YYYYMMDD','YYMMDD', 1976); put skip list (str); str = REPATTERN('19770101','YYMMDD','YYYYMMDD', 1976); put skip list (str); str = REPATTERN('20280101','YYMMDD','YYYYMMDD', 1976); put skip list (str); str = REPATTERN('19700101','YYMMDD','YYYYMMDD', 1976); put skip list (str); end;
This code sample prints the following:
19770101
20280101
770101
280101
Error raised. Outside century window.
None.
Description
The REPATTERN function takes a value containing a date in one pattern and returns that value converted to a date in a second pattern. The returned value has the attributes CHAR(m) NONVARYING where (m) is the length of the target pattern specified by p.