BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mohancs
Calcite | Level 5
Given Format - YYYYMM Required Format - YYMMDD (default dd to 01) Can anyone suggest how to do it in proc sql.?
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

4 REPLIES 4
LinusH
Tourmaline | Level 20

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

Data never sleeps
Steelers_In_DC
Barite | Level 11

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;

Reeza
Super User
Is it a character or SAS date value?
PGStats
Opal | Level 21

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

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 272762 views
  • 7 likes
  • 5 in conversation