0
votes

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.) 
2
How do you derive which day of the month it is? Should it always be in the middle of the month if it is lacking in the column?D. Josefsson
And as a side note: this site is not intended to be a code service. We are glad to help you with problems you have with your attempts to solve the problem. Please edit your question and add information about what you have tried so far. And also, please take some time to read through stackoverflow.com/help/how-to-ask. In this particular case it would be good if you explain what you have read about proc sql, different ways of converting character fields to number fields, and date formats.D. Josefsson

2 Answers

2
votes

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 ;
0
votes

You can try the below;

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