It seems that not all cells of the column are defined as numeric.
Maybe in some rows the cells are defined as text.
In such case you need convert the text into numeric and make it as date format:
data want;
set have(rename=(date=datex));
if lengthn(datex) = 5 then date = input(datex,5.);
else date = input(datex, mmddyy10.);
format date date9.;
run;
in case the dates in sas does not fit to the equivalent date of serial number of execl
you will need addapt it by a fix number of days.
SAS date count days since 01JAN1960 (serial number = 0);
while in excel 0 is: 00JAN1900
which means a difference of 21916 days.
Then change line to:
if lengthn(datex) = 5 then date = input(datex,5.) - 21916 ;
It kind of worked, the years for the respective serial numbers came out as follows
----> 2013 = 2073
----> 2015 = 2075
----> 2016 = 2076
@Okundaye1 wrote:
Also why is SAS reading Date as a character variable ?
Because you have some of the data entered as text that Excel did not treat as a date when entered.
The solution I have had to this is generally: 1) make sure the column is formatted as a consistent date format in Excel. 2) Export the data to CSV 3) read with an appropriate INFORMAT. If the data is relatively clean then that Informat may be mmddyy10. or similar. Sometimes Anydtdte32.
And then 4) beat the data source about the head and shoulders with a wet noodle about poorly entered data. 😉
The internal SAS value for 1/1/1960 is 0. The internal excel value for the same date is 21,916.
So after importing to SAS, you could
This will work as long as you have no dates preceding Mar 1, 1900. That's because visicalc mistakenly thought that 1900 was a leap year - an error preserved in its successor excel.
mk
@mkeintz wrote:
The internal SAS value for 1/1/1960 is 0. The internal excel value for the same date is 21,916.
So after importing to SAS, you could
- Subtract 21916 from the improperly imported date values.
- Assign a SAS format to the variable.
This will work as long as you have no dates preceding Mar 1, 1900. That's because visicalc mistakenly thought that 1900 was a leap year - an error preserved in its successor excel.
mk
AND Excel will accept 1/0/1900 as a valid "date" , enter 0 and format the cell as a date and see what you get.
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.