Help using Base SAS procedures

How to format date values in Proc SQL

Accepted Solution Solved
Reply
Established User
Posts: 1
Accepted Solution

How to format date values in Proc SQL

Given Format - YYYYMM Required Format - YYMMDD (default dd to 01) Can anyone suggest how to do it in proc sql.?

Accepted Solutions
Solution
‎03-28-2017 08:08 AM
Respected Advisor
Posts: 4,641

Re: How to format date values in Proc SQL

[ Edited ]

Depends whether your dates are like a, b or c in the following example 

 

data test;
  a = 201506; /* YYYYMM as a number */
  b = '01JUN2015'd; /* SAS date value with YYYYMM format */
  format b yymmn6.;
  c = "201506"; /* char version of the YYYYMM date */
run;

proc print; run;

proc sql;
select 
    mdy(mod(a, 100), 1, int(a/100)) as date_a format=yymmdd6.,
    b as date_b format=yymmdd6.,
    input(c, yymmn6.) as date_c  format=yymmdd6.
from test;
quit;

 

Result:

 dt.png

PG

View solution in original post


All Replies
Super User
Posts: 5,254

Re: How to format date values in Proc SQL

FORMAT= as a column option in either SELECT or CREATE statement,

Data never sleeps
Valued Guide
Posts: 858

Re: How to format date values in Proc SQL

Here you go:

 

data have;
informat date mmddyy10.;
format date mmddyy10.;
input date;
cards;
10/01/2015
;
run;

proc sql;
create table want as
select date format = date9.
from have;

Super User
Posts: 17,750

Re: How to format date values in Proc SQL

Is it a character or SAS date value?
Solution
‎03-28-2017 08:08 AM
Respected Advisor
Posts: 4,641

Re: How to format date values in Proc SQL

[ Edited ]

Depends whether your dates are like a, b or c in the following example 

 

data test;
  a = 201506; /* YYYYMM as a number */
  b = '01JUN2015'd; /* SAS date value with YYYYMM format */
  format b yymmn6.;
  c = "201506"; /* char version of the YYYYMM date */
run;

proc print; run;

proc sql;
select 
    mdy(mod(a, 100), 1, int(a/100)) as date_a format=yymmdd6.,
    b as date_b format=yymmdd6.,
    input(c, yymmn6.) as date_c  format=yymmdd6.
from test;
quit;

 

Result:

 dt.png

PG
☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 12039 views
  • 1 like
  • 5 in conversation