问题
I have dates in excel in the following format 02/15/2011. When I import to excel, the dates are numeric such as 40561. When I convert these in SAS using the code below, I get dates such as 04/01/1946. So far my code is:
data Reformat11;
set Old;
Amount1 = input(Amount, comma10.);
DateReceived2 = Input(PUT(DateReceived, 5.), MMDDYY10.);
Format DateReceived2 MMDDYY10.;
format DateApproved MMDDYY10.;
run;
Any other Suggestions?
回答1:
SAS knows how to import dates from Excel. What it cannot do is handle different data types for a single variable. SAS datasets are more like a database than a spreadsheet. If you can, make corrections in the source Excel file so that every cell in that column contains valid dates and your problem should disappear.
You will normally only see raw Excel number-of-days values when your column in Excel has mixed formats. So if some of the cells are character then the whole column will be character and SAS will get the number of days as a character string that represents that number. So in your example you would see the value '40561'
in SAS. So you first need to convert that to a number and then adjust for the different base dates used by SAS and Excel.
DateReceived2 = Input(DateReceived, 5.) + '30DEC1899'd ;
You can then attach any valid date format. I would avoid MMDDYY or DDMMYY as you will confuse half of your audience (do you mean April 1 or January 4?). Try YYMMDD or DATE.
format DateReceived2 yymmdd10.;
来源:https://stackoverflow.com/questions/54872050/importing-dates-from-excel-to-sas