BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GN0001
Barite | Level 11

Hello team,

I have a column of date which is all numeric, they are not characters. I need to format it as mm/dd/yyyy.

I do what I can, this doesn't get resolved.

the result has to be 10/24/1999

Regards,

Blue & Blue

Blue Blue
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If the value is numeric you just need to change the actual number involved to a date value and apply a format.

One example:

data example;
   x =  20191024;
   x = input(put(x,f8.),yymmdd8.);
   format x mmddyy10.;
run;

Which is easier than parsing out the month, day and year with other methods.

Caveat: if you have single digit month or day: 201911 (instead of 20190101) then you have more work to do.

 

 

View solution in original post

4 REPLIES 4
ballardw
Super User

If the value is numeric you just need to change the actual number involved to a date value and apply a format.

One example:

data example;
   x =  20191024;
   x = input(put(x,f8.),yymmdd8.);
   format x mmddyy10.;
run;

Which is easier than parsing out the month, day and year with other methods.

Caveat: if you have single digit month or day: 201911 (instead of 20190101) then you have more work to do.

 

 

GN0001
Barite | Level 11

Hello teammate,

 

This response saved my life. Thank you very much for it.

I need to know what 

put(x,f8.)

do.

Thanks for the response.

blue & blue

Blue Blue
Tom
Super User Tom
Super User

The INPUT() function converts strings into values based on the informat  being used.

But your variable is numeric, not a character strings.  So the PUT() function converts values into strings, based on the format being used.  The 8. format tells SAS to format the number as an 8 digit string.

GN0001
Barite | Level 11

Hello Tom,

What a great response.

 

Thanks,

Blue & Blue

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