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
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?)
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.
@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!
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.
@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).
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.