Formatting Date Variables

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Formatting Date Variables

I imported an Excel database into SAS and I'm trying to find the interval between 2 different dates: one formatted as DATE9. (ex. 03JUL2012) and the other as a character, $10. (ex. 8/24/2012). How can I convert the character variable to a the DATE9. variable?


Accepted Solutions
Solution
‎07-11-2013 03:43 PM
Contributor
Posts: 23

Re: Formatting Date Variables

Try the input function in a data step. Once you've converted the character variable to a date variable, it doesn't matter what format you use to view it in. It's stored as a number internally.

DATA test1;

     SET test;

     newdate = input(olddate, MMDDYY10.);

     datediff = newdate - otherdate;

     FORMAT newdate datediff DATE9.;

RUN;

View solution in original post


All Replies
Solution
‎07-11-2013 03:43 PM
Contributor
Posts: 23

Re: Formatting Date Variables

Try the input function in a data step. Once you've converted the character variable to a date variable, it doesn't matter what format you use to view it in. It's stored as a number internally.

DATA test1;

     SET test;

     newdate = input(olddate, MMDDYY10.);

     datediff = newdate - otherdate;

     FORMAT newdate datediff DATE9.;

RUN;

Contributor
Posts: 24

Re: Formatting Date Variables

Thank you! I couldn't figure out that I need to add the FORMAT statement.

☑ This topic is SOLVED.

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

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