Hello,
I am using SAS enterprise guide 7.1 and I need help in converting dates in one of my columns to date9 format. I have a column with the name "date_start" with dates as strings.
date_start:
21-02-2016 --> 21FEB2016
17-12-2015
23-02-2016
08-05-2016
These are all strings and I would like to convert them to DATE9 format. Here is my code below:
data new4;
set <file I'm working with>;
new_var = input(date_start, ddmmyy10.);
format new_var date09.;
run;
This image is after running the program. The last digit of the year is cut off and date_start2 does not have the DATE9. format.
Thank you for considering my question.
Your character dates appear truncated, note that you have no last digits for any of the years. Did you read these from a file?
If so, the import process appears incorrect.
It could be a display issue, but otherwise, your code should actually work, including the date09 portion.
@shril_21 wrote:
Hello,
I am using SAS enterprise guide 7.1 and I need help in converting dates in one of my columns to date9 format. I have a column with the name "date_start" with dates as strings.
date_start:
21-02-2016 --> 21FEB2016
17-12-2015
23-02-2016
08-05-2016
These are all strings and I would like to convert them to DATE9 format. Here is my code below:
data new4; set <file I'm working with>; new_var = input(date_start, ddmmyy10.); format new_var date09.;
run;
This image is after running the program. The last digit of the year is cut off and date_start2 does not have the DATE9. format.
Thank you for considering my question.
I was given a SAS data file and there was no importing (excel, etc.). The image in my question was from the output data. I'm not sure what the numbers mean in the date_start2 column as well. And I'm not sure why the dates are truncated.
In this picture, I imported these dates from an excel I quickly made to try examples. It seems to be working then.
Your code does not match your presented data (different variable names).
Your code will work with matching data, see here:
data want;
input _date_start :$10.;
date_start = input(_date_start,ddmmyy10.);
format date_start date9.;
cards;
21-02-2016
17-12-2015
23-02-2016
08-05-2016
;
run;
proc print data=want noobs;
run;
Result:
_date_ date_ start start 21-02-2016 21FEB2016 17-12-2015 17DEC2015 23-02-2016 23FEB2016 08-05-2016 08MAY2016
If this does not solve your problem, post your log ({i} button), and example data (data step with datalines, see my example and my footnotes).
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: