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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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