Home > Software engineering >  Change Datetime to ddmmyy in SAS
Change Datetime to ddmmyy in SAS

Time:02-19

I want to change a date variable from DateTime (e.g. 11NOV17:06:36:00) to show DDMMYY10. The informat is ANYDTDTM40 and type is numeric. The data sheet contains some 3600 observations and they all need to be changed. I have tried multiple combinations without luck - they all just give either "********" or "." as date results.

I thought this would be a simple task but it has taken me hours and I still can't figure it out. I am fairly new in SAS so please be descriptive when answering.

Hope you can help! Thanks

CodePudding user response:

data want ;
  set have ;
  date = datepart(datetime_variable) ; /* take date component of the datetime */
  format date ddmmyy10. ; /* format to ddmmyy10. */
run ;

CodePudding user response:

Behind the sceen, so called dates as well as datetimes are just double precision real numbers. However, if you assing a format date9. to a variable and you print it, SAS will print the date of being that many days after 1jan1960. Likewise, if you assing a format datetime19. to a variable and you print it date and time of that many seconds after the start of 1jan1960.

Sas has a function that calculates the days from the seconds: myDate = datepart(myDateTime);, but don't forget to format your variable too format myDate date9.;

  • Related