BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Rixile106
Fluorite | Level 6

Hi team.

can you please assist with converting a date field from DD/MM/YYYY to YYYY/MM/DD however the data type does not change to date format.

here is my code, however my out put looks like the below

Rixile106_0-1669234920929.png

DATA WANT;
	SET have;
	NEW_DAT = PUT ( INPUT(CREATEDDATE, MMDDYY10.), YYMMDDS10. );
	KEEP CREATEDDATE NEW_DAT;
RUN;

please assist

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Assuming that the little red A next the variable name in your PHOTOGRAPH of your data indicates that it is already character you should remove part of that function sandwich so that you create an actual numeric date value instead of another character string. 

 

Make sure you read the character string using an INFORMAT that matches the style of date strings that the variable contains.  There is no month number 15 so you cannot use the MMDDYY informat. 

 

You can then attach ANY date type format to the variable and SAS will display in the style that format generates.

Tom_0-1669235149182.png

DATA WANT;
  SET have;
  NEW_DAT = INPUT(CREATEDDATE, DDMMYY10.) ;
  format new_dat yymmdds10. ;
   KEEP CREATEDDATE NEW_DAT;
RUN;

 

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

Assuming that the little red A next the variable name in your PHOTOGRAPH of your data indicates that it is already character you should remove part of that function sandwich so that you create an actual numeric date value instead of another character string. 

 

Make sure you read the character string using an INFORMAT that matches the style of date strings that the variable contains.  There is no month number 15 so you cannot use the MMDDYY informat. 

 

You can then attach ANY date type format to the variable and SAS will display in the style that format generates.

Tom_0-1669235149182.png

DATA WANT;
  SET have;
  NEW_DAT = INPUT(CREATEDDATE, DDMMYY10.) ;
  format new_dat yymmdds10. ;
   KEEP CREATEDDATE NEW_DAT;
RUN;

 

Rixile106
Fluorite | Level 6

i have try your code, however am getting the below results

 

Rixile106_0-1669235874375.png

 

Tom
Super User Tom
Super User

Make sure to use an INFORMAT that can handle the strings.  There is no month number 15.

Reeza
Super User
Show your code and log.

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
  • 3517 views
  • 2 likes
  • 3 in conversation