Search code examples
datesasvarcharproc-sql

Getting Current date in SAS in YYMMDD10. Format in Date Datatype


I have a SQL Code which I am running in the SAS using proc SQL.

proc sql;
select col_A,col_B,put(date(),yymmdd10.) as col_C
from table_P;

create table_Q as 
(select * from table_P);
quit;

col_C is today's date and gets stored in the Varchar2 format. I want it to get stored in the date format. How do I do that? I want the date entries to look like '2022-05-04'. Even if the format of the date changes, how can I get into Date datatype from Varchar?


Solution

  • create table table_Q as 
        select col_A
                , col_B
                , date() format=yymmdd10. as col_c 
        from table_P;
    

    This will store col_C as a SAS date value, but apply the yyddmm10. format when presenting the data.