02-02-2016 11:27 AM
In SAS 9.2, when i read a text file using proc import to bring as a SAS dataset, one of the column which had date value [2015/08/13:12:00:00 AM] used to be imported as character format and the date value remained the same [2015/08/13:12:00:00 AM].
Now, in SAS 9.4 when i use the same proc import to import the same text file to SAS dataset, the column with the value [2015/08/13:12:00:00 AM] comes in as a date format with the value changed to 13AUG15:00:00:00. We just moved from 9.2 to 9.4.
Here is the code that was working for me in 9.2.
proc import datafile="C:\Desktop\Sample.txt"
I tried to use the option usedate=no but SAS throws me an error.
02-02-2016 11:38 AM
It looks like the change with 9.4 is to read the variable as DATE and format it with the default datetime format. You can change the format to display to mdyampm using the format of the same name.
If you want character variable (not useful) you can PUT the data into a new variable using the MDYAMPM. format.
You could also modify the code generated by PROC IMPORT
But why. A datetime variable is much more useful that a character string of the same data.
02-02-2016 12:01 PM
The mdyampm format changes the value to 8/13/2015 12:00 AM from [2015/08/13:12:00:00 AM]. Now, the issue is i am pulling the year and month value from that column and with the new format there is no leading '0' in front of the single date value like '8'. i cannot use substring to pull those values, since the date value is either a single or double digit.
Is there a format to get the leading zero in the value such as 08/13/2015 12:00 AM instead of 8/13/2015 12:AM
02-02-2016 12:34 PM
If you are extracting values from a datetime variable then there are easy ways to do so:
Year = year(datepart(datetimevariablename));
Month = month(datepart(datetimevariablename));
Day = day(datepart(datetimevariablename));
Not to mention formats that will display the value as desired such as DTDATE, DTMONYY, DTWKDATX, DTYEAR, DTYYQC.
02-02-2016 01:32 PM
As I mentioned and as @ballardw has demonstrated with and example, a DATETIME variable is much easier to work with than a character string.