Convert character strings to SAS dates

How to convert character values to SAS dates with INPUT and informats, what the conversion changes, how to handle US and international notation, and when a plain-text date is the better choice.

Dates often arrive in SAS as text: a CSV column read as character, a field typed by hand, or an export from another system. To sort, subtract, or group them as dates, you have to convert them into SAS date values. This review explains what that conversion changes, which tools fit which notations, and when keeping the original text is the safer choice. The code examples follow documented SAS behavior but were not run for this article, so test them against your own data and SAS release.

Short answer: is the conversion suitable for your use?

Convert the text when you need date arithmetic, sorting by time, intervals, or functions such as INTNX and INTCK. The benefit is that every date becomes one consistent number that SAS can calculate with. The main tradeoff is interpretation. You must tell SAS how to read the text, and a wrong guess about notation produces valid-looking but incorrect dates rather than an error. For example, 03/04/2025 can mean March 4 or April 3.

Plain text is preferable in three cases. The first is when you only display or pass through the value unchanged. The second is when the source notation is ambiguous and cannot be resolved. The third is when an audit or legal requirement means you must keep the original string exactly as received. In those cases, keep the character column, and if you also need a date, add a converted column beside it instead of replacing it.

What the conversion actually changes

A SAS date is a number: the count of days since January 1, 1960. Earlier dates are negative. Converting a character string to a date replaces stored characters with this number. The original text, including its separators, its order of day, month and year, and any leading zeros, is not part of the result.

Two separate mechanisms are involved, and they are easy to confuse:

  • Informat (reading): tells the INPUT function how to interpret the incoming text. It determines the stored value.
  • Format (display): controls how the stored number is shown in output, such as 04MAR2025, 03/04/2025 or 2025-03-04. Changing a format changes only the presentation, never the stored value.

This distinction matters for localization. Switching from MMDDYY10. to DDMMYY10. as a display format makes the same stored date appear differently. Using the wrong informat when reading stores a different date.

The core method: INPUT with an informat

The INPUT function reads a character value using an informat and returns a number. Assign a date format so the result is readable in output.

data want;
  set have;
  visit_date = input(visit_char, yymmdd10.);
  format visit_date date9.;
run;

Choose the informat that matches the text pattern. Commonly documented choices include:

Text pattern | Example input | Informat
Year-month-day (ISO style) | 2025-03-04 | YYMMDD10.
US month/day/year | 03/04/2025 | MMDDYY10.
Day/month/year | 04/03/2025 | DDMMYY10.
Day, month abbreviation, year | 04MAR2025 | DATE9.
Mixed or uncertain patterns | varies | ANYDTDTE.

In this table, the first three examples all represent March 4, 2025. The informat is what makes them equivalent.

Keeping the original variable name

A SAS variable cannot change from character to numeric in place. To keep the same name, rename the incoming character variable, convert it into a new variable that takes the original name, and drop the renamed copy only if you no longer need it.

data want;
  set have(rename=(visit_date=visit_date_char));
  visit_date = input(visit_date_char, mmddyy10.);
  format visit_date yymmdd10.;
  drop visit_date_char;
run;

Strings that contain a time

If the text includes a time, you have two options. You can read it with a datetime informat and extract the date with DATEPART. Alternatively, ANYDTDTE. can return just the date portion from many datetime-style strings. The DATEPART route is more explicit about what is being read.

Localization: US and international notation

The main risk for a US audience is assuming that every slash-separated date is month first. Data from many other regions puts the day first, and numeric dates with a day of 12 or less parse successfully either way. When reading such dates, SAS does not warn you that the order was wrong.

  • If a source consistently uses one order, name that order explicitly with MMDDYY. or DDMMYY. rather than relying on automatic detection.
  • ANYDTDTE. resolves ambiguous numeric dates using the DATESTYLE system option, whose default depends on the LOCALE setting. Set DATESTYLE explicitly (for example, options datestyle=mdy;) so the result does not change when the program runs under a different locale.
  • Two-digit years are interpreted using the YEARCUTOFF system option. Check its value in your environment rather than assuming a default, especially for birth dates or historical records.
  • Month names in text, such as MAR, are read in English by standard informats. Localized month names may need the NL informats and an appropriate LOCALE. Confirm this against your SAS documentation, because this review has no tested evidence for specific languages.

If a single column mixes orders, for example because records came from different countries, no informat can resolve the ambiguity. Split the data by source, or keep the original text and flag those rows.

Checking for silent failures

When text does not match the informat, INPUT returns a missing value and the log reports an invalid argument. The ?? modifier suppresses those log messages, which keeps the log clean but also hides problems. Whichever approach you use, compare the result against the source.

data want check;
  set have;
  visit_date = input(strip(visit_char), ?? yymmdd10.);
  format visit_date date9.;
  if missing(visit_date) and not missing(visit_char) then output check;
  output want;
run;

Missing values reveal strings that could not be parsed. They do not reveal day and month swaps, which still produce valid dates. To catch those, review a sample of converted values against the source text, and look for rows where the first number exceeds 12 as evidence of which order the source actually uses.

Will the result stay usable after copying or exporting?

Inside SAS, the converted value is stable. Once it leaves SAS, whether the format travels with it depends on how you export it. If only the raw number is carried over, a recipient sees a value such as 23804 instead of a date. Other systems also count days from different starting points. For example, spreadsheet serial dates do not use the 1960 origin, so pasting raw SAS date numbers into a spreadsheet and formatting them as dates gives wrong results.

  • For files shared with people or other software, write dates as formatted text in an unambiguous notation. Year-month-day (YYMMDD10. or E8601DA.) avoids the US versus international order problem.
  • If a recipient needs a numeric date, convert it explicitly on their side rather than relying on an automatic interpretation.
  • For readers who may not know the notation, a format with a month name, such as DATE9. or WORDDATE., avoids order confusion. This review has no test evidence on how screen readers or other assistive technology pronounce these styles, so check with your actual audience if that matters.
  • Copying values from SAS output windows or reports copies the displayed, formatted text, not the stored number. Treat copied values as plain text that needs re-reading on the other side.

Gaps in this review

No test results, version-specific measurements or tool comparisons were supplied for this article. The behavior described here reflects general, documented SAS principles: numeric date values, informats for reading, formats for display, and the DATESTYLE and YEARCUTOFF options. Default option values, NL informat coverage for specific languages, and how export procedures handle formats can vary by SAS release and configuration. Verify these in your environment before relying on them in production.