Help using Base SAS procedures

Convert of Best 12. to YYMMDDN8.

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Convert of Best 12. to YYMMDDN8.

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


Accepted Solutions
Solution
‎07-16-2015 08:57 AM
Respected Advisor
Posts: 3,777

Re: Convert of Best 12. to YYMMDDN8.

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


All Replies
Super Contributor
Posts: 305

Re: Convert of Best 12. to YYMMDDN8.

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;

Valued Guide
Posts: 858

Re: Convert of Best 12. to YYMMDDN8.

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;

Super User
Super User
Posts: 7,421

Re: Convert of Best 12. to YYMMDDN8.

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

data want;

  set have;

  format date yymmdd8.;

run;

Solution
‎07-16-2015 08:57 AM
Respected Advisor
Posts: 3,777

Re: Convert of Best 12. to YYMMDDN8.

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
Super User
Super User
Posts: 7,421

Re: Convert of Best 12. to YYMMDDN8.

Yes, you are quite correct.  Ignore my post.

☑ This topic is solved.

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

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