BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

data mydate (keep=ln_no mydate);

set date1;

run;

output is

ln_no    mydate

011     09JUN2015:00:00:00.000

 

I tried using this
newdt = datepart(mydate);

format newdt mmddyy10.

For some reason the newdt turns into a numeric and looses its date datatype.

I want to extract the 09JUN2015 since the datepart function on this particular field does not convert to a date.

 

3 REPLIES 3
Reeza
Super User

 

For some reason the newdt turns into a numeric and looses its date datatype.

 

SAS Dates, times and datetimes are stored as numeric variables. 

 

Is your starting variable a numeric variable with a datetime format?

If it's character, DATEPART() will not work. In that case, you can use SCAN instead with the : as the delimiter and then use INPUT to convert it to a SAS date. 

Shmuel
Garnet | Level 18

It seems that the variable MYDATE is a char type - that is a character string, 

then you can read it either by defining its length $9 with informat date9. (neglect the time part)

or if you have it as one char type variable of length $24 then:

     datex = scan(mydate,1,':');

     date = input(datex,date9.);

     format date date9.;

 

shindekiranp
Calcite | Level 5

Great info,it worked!!

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!

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.

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
  • 3 replies
  • 12780 views
  • 0 likes
  • 4 in conversation