## How to convert date vari from character (\$33.) to date (date9.) format

Solved
Occasional Contributor
Posts: 12

# How to convert date vari from character (\$33.) to date (date9.) format

Hi there,

I am a beginner programmer trying to convert a date variable from a character format into one of the standard SAS date formats (e.g., date9.).

The variable (surgerydate) is in \$33. format (character) and dates are written as DD-MMM-YYYY (e.g., 26-MAY-2008).

Could anyone suggest some code to solve this?

Thanks!

Lindsay

Accepted Solutions
Solution
‎03-08-2014 06:34 PM
Posts: 4,736

## Re: How to convert date vari from character (\$33.) to date (date9.) format

Use INFORMATS to convert a text string to a numeric value (a SAS date value is a numeric value containing the number of days since 1/1/1960).

SAS(R) 9.4 Formats and Informats: Reference

data sample;

attrib

date_as_string length=\$33

date_as_SAS_date_value length=8 format=date9.

;

date_as_string='26-MAY-2008';

date_as_SAS_date_value=input(date_as_string,date11.);

run;

All Replies
Solution
‎03-08-2014 06:34 PM
Posts: 4,736

## Re: How to convert date vari from character (\$33.) to date (date9.) format

Use INFORMATS to convert a text string to a numeric value (a SAS date value is a numeric value containing the number of days since 1/1/1960).

SAS(R) 9.4 Formats and Informats: Reference

data sample;

attrib

date_as_string length=\$33

date_as_SAS_date_value length=8 format=date9.

;

date_as_string='26-MAY-2008';

date_as_SAS_date_value=input(date_as_string,date11.);

run;

Occasional Contributor
Posts: 12

## Re: How to convert date vari from character (\$33.) to date (date9.) format

Thanks so much - worked like a charm

🔒 This topic is solved and locked.