Sample 24610: SAS date formats with or without separators

Write date values in the form of DDMMYY, DDMMYYYY, MMDDYY,
MMDDYYYY, YYMMDD, or YYYYMMDD with or without separators.

Note: Almost all of the SAS date formats can produce a two-digit
or four-digit year. Even though the name of the format might
imply a two-digit year, like MMDDYYw., you can produce a four-digit year by increasing the width specification.

These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.

/* Sample 1: New formats in SAS Version 7 */
/* */
/* In SAS Version 7 and beyond, SAS provides new date formats that allow */
/* you to specify the type of separator, or no separator when */
/* writing out date values. The format names are: DDMMYYxw., */
/* MMDDYYxw., and YYMMDDxw. where x specifies the type of separator */
/* or no separator. Replace the x with one of the following letters */
/* to indicate the type of separator: B for blank, C for colon, */
/* D for dash, N for no separator, P for period, or S for slash. If */
/* selecting a separator remember to include it in the width of the */
/* output value. */
data _null_;
date='19JAN2000'd;
put date= yymmddn8.;
put date= ddmmyyc10.;
put date= mmddyyp8.;
put date= yymmdds10.;
put date= ddmmyyd8.;
put date= mmddyyd10.;
run;
/* Sample 2: Prior to SAS Version 7 formats */
/* */
/* Prior to SAS Version 7, in order to produce dates */
/* with a specific separator or produce dates with a 4 digit year */
/* and no separator, you must create a character variable */
/* using the PUT function along with the date format closest to */
/* the form of the date you desire. Use the COMPRESS function to */
/* remove the default separator, or use the TRANSLATE function to */
/* replace the default separator with the desired separator. */
data _null_;
date='19JUL2000'd;
sasdate1=compress(put(date,yymmdd10.),'-');
sasdate2=translate(put(date,yymmdd10.),'/','-');
put sasdate1=;
put sasdate2=;
run;

These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.