newb
newb

Reputation: 77

How to convert characters to date in SAS proc sql

I have a column of data named yearmonth stored as characters data. I want to convert this column into SAS date in another column with format dd/mm/yyyy.

for example lets say one of the data is 201201. I want to convert it into 15/01/2012. The problem is I can only use the proc sql and unable to changed the data. Anybody can help me with this problem?

Edit: This is the one I have done :

INPUT("01/" || substr(t1.Yearmonth, 5,2) ||"/"|| substr(t1.Yearmonth, 1, 4),ddmmyy10.) 

Upvotes: 0

Views: 13330

Answers (2)

Nadeem_MK
Nadeem_MK

Reputation: 7699

You can try the below;

data test;
  mydate='20120115';
  date_new = input(mydate, ddmmyy10.);
  format date_new date10.;
run;

Upvotes: 0

Bendy
Bendy

Reputation: 3576

Your dataset with character YYYYMM dates:

data input ;
input date $ ;
cards ;
201201
;run ;

You can create a new variable as below:

proc sql ;
  create table output as
  select date, input(date, yymmn6.)+14 as newdate 
  from input
;quit ;

Upvotes: 2

Related Questions