BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bbb_NG
Fluorite | Level 6


I have a variable called birthday in datatime format like "12NOV1935:00:00:00",

How can I just pick out month and day and add year 2012 to form "12NOV2012:00:00:00" (in sas datetime format)

or ""12NOV2012" (in sas date format)?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Bago
SAS Employee

Hey,

You can use function datepart to extract the date. You can use functions month & day to extract month & day information. You can use function mdy to construct the date "format" and you can use dhms to reconstruct the datetime format.

/* example code */

data _null_;

x = "12NOV1935:00:00:00"dt;

datepart = datepart(x);

put x;

put datepart date9.;

mon = month(datepart);

day = day(datepart);

put mon=;

put day=;

mdyt = dhms(mdy(mon,day,2012),0,0,0);

put mdyt datetime18.;

run;

More information about aformentioned functions can be found at Functions and CALL Routines (http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245852.htm ).

Kind regards,

Bago

View solution in original post

4 REPLIES 4
Bago
SAS Employee

Hey,

You can use function datepart to extract the date. You can use functions month & day to extract month & day information. You can use function mdy to construct the date "format" and you can use dhms to reconstruct the datetime format.

/* example code */

data _null_;

x = "12NOV1935:00:00:00"dt;

datepart = datepart(x);

put x;

put datepart date9.;

mon = month(datepart);

day = day(datepart);

put mon=;

put day=;

mdyt = dhms(mdy(mon,day,2012),0,0,0);

put mdyt datetime18.;

run;

More information about aformentioned functions can be found at Functions and CALL Routines (http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245852.htm ).

Kind regards,

Bago

bbb_NG
Fluorite | Level 6

Bago,thanks for your example code.I need this function dhms.And it solved my problem.Very thanks.

and sorry that I can not find a correct answer click in this page.

Dawn

ballardw
Super User

Was the 1935 year value expected to be 2012 and you are getting it erroneously? If so it is probably a good idea to look at how the data is getting into SAS and the source as prevention is way better than fixing.

bbb_NG
Fluorite | Level 6

ballardw ,thanks for taking time to view my requests.sorry for having not explain well, in fact i want all value in this birthday variable to be replaced with year 2012 to calculate something.anyway bago help to sovle this .Thank you.

dawn

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1082 views
  • 1 like
  • 3 in conversation