SAS Programming

DATA Step, Macro, Functions and more
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.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 5138 views
  • 2 likes
  • 3 in conversation