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.
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
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
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
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.
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.