BookmarkSubscribeRSS Feed
dominicrb
Calcite | Level 5

Hi everyone,

I have a data set (data_set11) where the format of a variable (Decision_Date) is: 26NOV2010:00:00:00.000.

I would like to change it to 2010/11/26 AND extract the month (11).

Thank you

2 REPLIES 2
ballardw
Super User

The value example you display means the variable is likely a DATETIME variable unless it is character, in which formats won't help a lot.

If it is datetime, there are limited SAS supplied formats but E8601DA10. or E8601DN10. come closest depending on whther you want single digit months and days to appear with a leading 0. There will be - instead of /

Or convert it to an actual date as Decision_date= datepart(Decision_date);

If you want a new variable then

month=month(datepart(Decision_date)); If you converted it to a date as above then

month= month(Decision_date);

SOORISAS
Calcite | Level 5

Hi Dominic,

If you want to change your date directly to month, this is the code.

data one;

input date:datetime22.;

Month_of_your_date=month(datepart(date));

datalines;

26NOV2010:00:00:00.000

;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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