BookmarkSubscribeRSS Feed
PriyaL
Fluorite | Level 6

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.

3 REPLIES 3
Astounding
PROC Star

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.

PriyaL
Fluorite | Level 6
The first 3 characters will only display the month whereas I need the month and year.
Astounding
PROC Star

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 9000 views
  • 0 likes
  • 2 in conversation