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
PROC Star

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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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