Help using Base SAS procedures

SAS DATATIME formate puzzle

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 99
Accepted Solution

SAS DATATIME formate puzzle


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.


Accepted Solutions
Solution
‎05-09-2012 07:23 AM
SAS Employee
Posts: 7

Re: SAS DATATIME formate puzzle

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


All Replies
Solution
‎05-09-2012 07:23 AM
SAS Employee
Posts: 7

Re: SAS DATATIME formate puzzle

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

Frequent Contributor
Posts: 99

Re: SAS DATATIME formate puzzle

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

Super User
Posts: 10,500

Re: SAS DATATIME formate puzzle

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.

Frequent Contributor
Posts: 99

Re: SAS DATATIME formate puzzle

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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