Hello everyone,
I am having a little bit of trouble with some dates. I uploaded an excel and imported it to a SAS database with dates in format dd/mm/yyyy. I used the following code to change it to SAS date but I get missings in return. I have tried DATE9. and DDMMYY10.
Here is the code:
data dates;
set previous;
admdate=input(adm, DDMMYY8.);
format admdate;
run;
Thank you
Show us the unformatted values of ADM in your SAS data set named PREVIOUS.
Before changing anything check what type of variable you have in the SAS dataset first.
It is in numeric format and in DDMMYYYY10.
The thing is that I want to change it to SAS date format.
Thank you
A FORMAT in SAS is instructions for how to display values as text. If the variable is numeric then you have numeric values in the variable.
Since the variable is numeric already you can replace the existing number with the date value and then just attach the format you want to use to display it.
So if you have a dataset named HAVE with a numeric variable named DATE with values like 13,102,021 and 01,051,989 then you can use a step like this to create a new dataset named WANT that has the numbers converted into dates that will display by default as string in MM/DD/YYYY pattern.
data want;
set have;
date=input(put(date,z8.),mmddyy8.);
format date mmddyy10.;
run;
@MerAgSo wrote:
It is in numeric format and in DDMMYYYY10.
The thing is that I want to change it to SAS date format.
Thank you
There is no SAS format named DDMMYYYY. There is one named DDMMYY and others with a 7th letter to indicate the type of separator to use between the day month and year values.
And what does the 10 mean there? If you have a series of digits in DDMMYYYY style the longest it can be is 8 characters. The only reason you would need 10 is to have room for the delimiter. But there is no place to store a delimiter in a numeric variable.
Did you just mean that the digits of the number look like they could be the day,month and year of a date value? Then convert the number to a string and then back to a date value using PUT() and INPUT() functions.
date=input(put(date,z8.),ddmmyy8.);
And if you mean that the variable is numeric and has the DDMMYY format attached to it already then you already have date values. So what is it you want to change? Do you want to display the values in a different way? Then use a FORMAT statement to attach a different format to the variable.
Sorry, the format is DDMMYY10. considering separators (/). I know this a date format but I want the numeric value given for SAS date value (The numeric value which counts days from January 1st, 1960). I need this in order to estimate several day differences among dates.
@MerAgSo wrote:
Sorry, the format is DDMMYY10. considering separators (/). I know this a date format but I want the numeric value given for SAS date value (The numeric value which counts days from January 1st, 1960). I need this in order to estimate several day differences among dates.
It is the number of days already. To get the difference in days between two dates just subtract.
days_since = date2 - date1 ;
days_since_1960 = date ;
days_since_2000 = date - '01JAN2000'd ;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.