BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

I have the dataset A which has Numeric Date

 

20120321

20130823

20220914

20200813

I want to change the format like below. And want to be the same numeric.

2012-03-21

2013-08-23

2022-09-14

2020-08-13

 

thanks in Advance

6 REPLIES 6
PaigeMiller
Diamond | Level 26

So, please confirm that the first dates you show, like 20120321 are numeric. Also please tell us if the variable is UN-formatted or formatted (and what is the format?)

--
Paige Miller
Smitha9
Fluorite | Level 6

Smitha9_1-1693406014732.png

 

Kurt_Bremser
Super User

So you don't have dates, you have mostly useless garbage which looks like dates, but must be converted to be properly used in analysis.

You need to do

date = input(put(date,z8.),yymmdd8.);
format date yymmdd10.;

But you are probably better off going back to the process that brings the data into SAS and fixing it.

PaigeMiller
Diamond | Level 26

@Smitha9 wrote:

I have the dataset A which has Numeric Date

 

20120321

20130823

20220914

20200813


Speaking of fixing the process ... @Smitha9 you are not new here, from now on please provide data as working SAS data step code (examples and instructions) so we don't have to ask these questions about is it formatted and what is the format. Just provide that information by providing data in the requested format, thanks!

--
Paige Miller
Astounding
Opal | Level 21

While the advice you have received is good, you can actually do what you asked for originally.  It's not best practice to keep dates in this form, but you can do it and change the display format by creating your own format:

proc format;
picture mydate  1-99999999 = '9999-99-99';
run;

Then whenever printing the data, add:

format my_unspecified_date_variable_name mydate.;

You may need to re-create the format in any program that needs to use that format.

 

You are likely better off putting real dates into the data instead of these numbers that only look like dates but really aren't.

PaigeMiller
Diamond | Level 26

@Astounding wrote:

 

You are likely better off putting real dates into the data instead of these numbers that only look like dates but really aren't.


Yes, that's the important message here. If it is not a real date, but just looks like a date, you can't do arithmetic with it (Example: compute what date is 6 months before this date) except by inventing your own SAS code to do this (but since SAS has already done this on real dates, so you don't have to; thus use real dates).

--
Paige Miller

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 338 views
  • 0 likes
  • 4 in conversation