DATA Step, Macro, Functions and more

Convert date to character string

Reply
Occasional Contributor
Posts: 14

Convert date to character string

Hi,

 

I am trying to find a way to convert a date into a like for like character string to I can merge in data using the date as a variable.

For example

 

ReferenceDatedate2
89374631MAR2002:00:00:00.000Mar-02

 

Where date2 is the datepart(date) formatted using monyy5.

I would like to make a variable date3 that is a character replica of date2 as I don't want to deal with days in the merge.

 

Does anyone know an easy way to do this?

Thanks.

Super User
Posts: 5,085

Re: Convert date to character string

A reasonable way:

 

length date3 $ 3;

date3 = put(date2, monyy5.);

 

Because of the LENGTH statement, there is only room to store the first 3 characters.

Occasional Contributor
Posts: 14

Re: Convert date to character string

The first 3 characters will only display the month whereas I need the month and year.
Super User
Posts: 5,085

Re: Convert date to character string

OK, then give DATE3 a length of $5 instead of $3.

Ask a Question
Discussion stats
  • 3 replies
  • 276 views
  • 0 likes
  • 2 in conversation