BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
george_gt
Calcite | Level 5

Does anyone know how to convert number format into date format?  For example, the following shows what my data looks like:

Date

20060306
20040727
20040407
20010423

All of data is shown as the number format BEST12. Informat 12. I want to convert them into these format YYMMDDN8. Informat YYMMDD6.  in order to do a  match afterwards. Could anyone tell me how to do it? Many  Thanks in advance.

george

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

Are you sure?  I don't think associating YYMMDD8 with a numeric variable that does not contain a "SAS Date" will produce the correct result.  You have to read the "date string" using the proper date INFORMAT.

data have;
   input date;
   x = date;
   format date yymmdd8.;
  
cards;
20060306
20040727
20040407
20010423
;;;;
   run;
proc print;
  
run;

data todate;
   set have;
   sasdate = input(put(date,8.),yymmdd8.);
   format date;
   format sasdate yymmddn8.;
  
run;
proc print;
  
run;
proc print;
  
format _all_;
   run;

Capture.PNG

View solution in original post

5 REPLIES 5
Loko
Barite | Level 11

hello,

data have;

input Date;

datalines;

20060306

20040727

20040407

20010423

;

run;

data want;

set have;

date_c=put(date,8.);

date_n=input(date_c,yymmdd8.);

format date_n yymmddn8.;

run;

Steelers_In_DC
Barite | Level 11

data have;

infile cards;

input date;

format date best12.;

cards;

20060306

20040727

20040407

20010423

;

run;

data want;

format  date2 yymmddn8.;

set have;

date2 = input(put(date,8.),yymmdd8.);

run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You could just stop at the format statement (same test data):

data want;

  set have;

  format date yymmdd8.;

run;

data_null__
Jade | Level 19

Are you sure?  I don't think associating YYMMDD8 with a numeric variable that does not contain a "SAS Date" will produce the correct result.  You have to read the "date string" using the proper date INFORMAT.

data have;
   input date;
   x = date;
   format date yymmdd8.;
  
cards;
20060306
20040727
20040407
20010423
;;;;
   run;
proc print;
  
run;

data todate;
   set have;
   sasdate = input(put(date,8.),yymmdd8.);
   format date;
   format sasdate yymmddn8.;
  
run;
proc print;
  
run;
proc print;
  
format _all_;
   run;

Capture.PNG
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, you are quite correct.  Ignore my post.

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch 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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 16814 views
  • 5 likes
  • 5 in conversation