BookmarkSubscribeRSS Feed
shril_21
Calcite | Level 5

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.

Capture.PNG

Thank you for considering my question.

 

4 REPLIES 4
Reeza
Super User
The format is date9, not date09.
Reeza
Super User

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.

Capture.PNG

Thank you for considering my question.

 


 

shril_21
Calcite | Level 5

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.

 

Capture1.PNG

 

In this picture, I imported these dates from an excel I quickly made to try examples. It seems to be working then. 

Kurt_Bremser
Super User

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).

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

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
  • 4 replies
  • 21917 views
  • 0 likes
  • 3 in conversation