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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1885 views
  • 1 like
  • 3 in conversation