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

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

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
Respected Advisor
Posts: 3,887

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;

View solution in original post


All Replies
Solution
‎03-08-2014 06:34 PM
Respected Advisor
Posts: 3,887

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 Smiley Happy

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 2988 views
  • 1 like
  • 2 in conversation