I have date format 16-Oct in excel. How can I import in date format in SAS?
For example:
data a;
infile "&input.&data." delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
informat date yymmdd6. ;
format date yymmdd6. ;
input date;
run;
This code gives missing values in date column.
Thanks.
Do you have an Excel file or a text file? You cannot read an Excel file as if it was a text file. To read from an Excel file you will need to use PROC IMPORT or use LIBNAME statement to point at the workbook and read the sheets out as datasets.
If you do have a text file then you need a different informat. The YYMMDD informat expects to have numeric Year, Month and Day values, in that order. Try using the ANYDTDTE. informat instead. Otherwise read it as a string and convert the string into a format that one of the SAS date informats can read.
It's excel file. There are more than 200 variables and more than 10 date columns. Other date formats read well, but this date format is not working. I also tried using ANYDTDTE but didn't work.
What date do you think 16-Oct represents? It is the 16th of October of the current year? Is any day in in October of 2016? Or perhaps any day in October of 1916?
It is October of 2016.
@sasuser1031 wrote:
It is October of 2016.
I suggest going into Excel, finding that cell and using the Format Cells option set that cell to a format that shows day, month and year. Every value I have seen in Excel that is an actual date that looks like 16-Oct is 16 Oct of the current year when entered. Month and year normally appear as Oct-16. If you have created a custom date appearance that wouldn't be the case but I see very few people do that.
And perhaps set the entire column the selected the date format. You might find that your "dates" are actually character or possibly even worse a mixture of character and Excel date values.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.