scottlittle scottlittle - 2 months ago 22
SQL Question

Converting text field to date in SAS SQL

I am trying to convert a text field from a SAS table with the form '2014-12-31' into a another SAS table as a date field. The below does not work:

proc sql outobs=50;
create table Dbtr_Clnt_Generl_Inf as
select FACS_Schema_ID '',
'DBACCT*'n as ACCOUNT_NUM '',
DBLSTDTI as Date_Listed format=date09.
from sqlsrv10.Acct_Dbtr_Clnt_Generl_Inf;
quit;


I get the following error:
ERROR: Character expression requires a character format.

Joe Joe
Answer

You use INPUT to convert types in SAS.

proc sql outobs=50;
create table Dbtr_Clnt_Generl_Inf as
  select FACS_Schema_ID '',
        'DBACCT*'n as ACCOUNT_NUM '',
        input(DBLSTDTI,yymmdd10.) as Date_Listed format=date09.
  from sqlsrv10.Acct_Dbtr_Clnt_Generl_Inf;
quit;

That is most likely the correct informat based on your question.