Home > Software design >  SAS Format DATE9. to DDMMYYd10. in select statement
SAS Format DATE9. to DDMMYYd10. in select statement

Time:03-11

How can I format a DATE9. date to DDMMYYd10. in my select statement?

PROC SQL;
 CREATE TABLE TEST AS
 SELECT BIRTH_DT
 FROM CUSTOMER
QUIT;

I tried:

PROC SQL;
 CREATE TABLE TEST AS
 SELECT BIRTH_DT FORMAT=DDMMYYd10.
 FROM CUSTOMER
QUIT; 

Also tried:

PROC SQL;
 CREATE TABLE TEST AS
 SELECT DATEPART(BIRTH_DT) FORMAT=DDMMYYd10. AS BIRTH_DT
 FROM CUSTOMER
QUIT; 

But this raises an error.

Current output is 28MAY1960 and I need 28-05-1960

CodePudding user response:

You are getting an error because you are missing a semi-colon ; after the from statement. Also the datepart function is not needed.

data have;
  dt_birth = '28MAY1960'd;
  format dt_birth date9.;
run;

proc sql;
    create table want as
    select dt_birth format=ddmmyyd10.
    from have;
quit;
28-05-1960
  • Related