SAS (Base SAS)+
*=============================================================================;
* Convert date values to formatted character strings
*=============================================================================;
*-----------------------------------------------------------------------------;
* Create sample data with SAS date values
*-----------------------------------------------------------------------------;
data dates;
input dt :date9.;
format dt date9.;
datalines;
15JAN2025
30JUN2025
01DEC2025
;
run;
*-----------------------------------------------------------------------------;
* Convert to various character formats using PUT
*-----------------------------------------------------------------------------;
data formatted;
set dates;
length char_date9 $9 char_iso $10 char_e8601 $10 char_custom $11;
* DATE9. format: 15JAN2025;
char_date9 = put(dt, date9.);
* YYMMDD10. format: 2025-01-15;
char_iso = put(dt, yymmdd10.);
* E8601DA. format: 2025-01-15 (explicit ISO 8601);
char_e8601 = put(dt, e8601da.);
* Custom format with PUTN: DD-MON-YYYY;
char_custom = put(dt, date9.);
char_custom = substr(char_custom, 1, 2) || '-' ||
substr(char_custom, 3, 5) || '-' ||
substr(char_custom, 6, 9);
run;
proc print data=formatted noobs;
run;- We start with three SAS date values and convert each to character strings in several common clinical formats.
put(dt, date9.)produces the standard SAS display format "15JAN2025" β this is the format most commonly used in clinical listings and datasets.put(dt, yymmdd10.)produces "2025-01-15", which is the ISO 8601 layout expected in SDTM and ADaM character date variables.put(dt, e8601da.)also produces "2025-01-15" β it is the explicit ISO 8601 date format, functionally identical to yymmdd10. for simple dates.- SAS date formats like DATE9. produce uppercase month abbreviations by default, so no extra step is needed for clinical display standards.
- For a custom layout like "DD-MON-YYYY", we apply PUT with DATE9. first and then insert dashes using SUBSTR and concatenation.
- The LENGTH statement pre-allocates character variables to the correct width, preventing truncation or excess padding.
- We run PROC PRINT and confirm each column contains the expected format β especially the ISO columns, which TFL headers and footnotes often require.