Hi
I had dates in the format: DD/MM/YYYY
I wanted these to be represented as numbers. So I did:
data have; set have;
date2= date*1;
run;
This command produced large negative numbers. No decipherable ddmmyyy was found (im looking for numeric dates without the commars).
I then, performed the following command:
data have; set have; format date ddmmyyn8.; run;
This produced a pleasing result in the form of ddmmyyyy.
But however SAS still didnt recognise my date as numeric. When I multipled by 1, I still received large negative numbers. How do I solve this problem?
I need ddmmyyyy to be in number form in order fo this command to work:
data have; set have;
IF DATE>0 then MMYY = substr(DATE, 4, 7);
RUN;
How about combine code from Ksharp and Alpay?
proc import datafile='c:\temp\test.dbf' out=have dbms=dbf replace;run;
data want;
set have;
newdate = INPUT(PUT(date,ddmmyyn8.),best12.);
run;
Haikuo
Hi,
If you have posted some sample data it would have helped...
data have;
input date $;
cards;
30102011
;
run;
data want;
set have;
newdate=input(date,ddmmyy8.);
format newdate date9.;
run;
Thanks,
Shiva
hmm i follwed your codes but didnt seem to work. I received an error message.
If you could help me identify what im doing wrong that would be rlly helpful. Here is my data:
Your file is dbf file and the date variable has already been numberic after importing SAS and its formate is not DDMMYY but MMDDYY.
proc import datafile='c:\test.dbf' out=have dbms=dbf replace;run; data want; set have; mmyy=put(date,mmyys.); run;
Ksharp
Hey thanks for your input.
BUT In my dataset would like dates to be numbers and without the '/'
To illustrate: if the date was 31/12/2011 I would like it to be 31122011.
And if I multiply 31122011 by 1 it should still be 31122011. Not a large negative number (I commonly find I can't plus or minus numbers to the date formats)
Hi,
I dont understand the logic why you want the date in this format 31122011 .Any how you can just apply the format like this..SAS internally stores date values in numbers itself.
data have;
set dbf;
date1=date*1;
format date1 mmddyy7.;
RUN;
Thanks,
Shiva
Hi
I would like the date in the numeric format because then I can plus ten years to the year or minus ten years to the year. I'm looking to edit my dates later on my in my analysis.
Via your method date 1 still is not recognised as a number. When you multiply by 1 or minus 1 I am still receiving a large negative. Furthermore, is it possible to have it in the format ddmmyyyy OR yyyymmdd?
Date values are stored as the number of days since 1/1/1960 in SAS and displayed with date formats like mmddyys10. (MM/DD/YYYY)/date9.(DDMONYYYY), etc.
SAS has specific functions to do date arithmetic like increment/decrement dates by week/month/quarter/year or count the date intervals between two dates.
For some examples/details, please see Art Carpenter's paper on using SAS dates and times http://www.lexjansen.com/pharmasug/2005/tutorials/tu01.pdf
The following code snippet will turn a date value 31/12/2012 into an integer value of 31122012.
data _null_;
date = '31Dec2012'd;
newdate = INPUT(PUT(x,ddmmyyn8.),best12.);
put newdate=;
run;
using this method I only have 1 observation. I have attached my data above. What can I change '31dec2012' to read all my data not just 1?
How about combine code from Ksharp and Alpay?
proc import datafile='c:\temp\test.dbf' out=have dbms=dbf replace;run;
data want;
set have;
newdate = INPUT(PUT(date,ddmmyyn8.),best12.);
run;
Haikuo
Once you understand how SAS stores date values, this would be the way to add 10 years:
data want;
set have;
newdate = intnx('year', date, +10, 'same');
format date newdate ddmmyyn8.; /* or any other date format you would like to see */
run;
But first, it is important to understand SAS's date scale.
Good luck.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.