08-02-2013 03:51 PM
I've checked the archives and can't find the correct combination of clues for my problem...
I am relatively new to reading data directly from Excel and dbf files. I imported a dbf into a sas library and the date is formatted as for example, 06/04/13. Normally when I import SAS converts it to the integer automatically, but this time for whatever reason it has retained the mmddyy10. format. How do I reformat it to the simple integer value for a sas date?
08-02-2013 04:30 PM
08-02-2013 04:59 PM
I see two choices.
1) SAS did import it as a date and has just assigned a different format than you are used to.
2) SAS imported the variable as a character string. In which case you can use INPUT() function to create a new variable that is an actual date variable.
Here is a simple test that will help you tell which it is.
set MYDATA ;
put datevar= / datevar= best12. / datevar=date9. ;
If it is a date then you will get something like this:
If it is character you will get
NOTE 484-185: Format $DATE was not found or could not be loaded.
08-05-2013 08:55 AM
The code withe the back slashes in it didn't do anything.
I know It is a date format because when I right-click the column in SAS explorer, it is listed as format mmddyy8. and informat yymmdd8..
Also when I prob print with a format statement I can get it to change the output form.
Alternatively, one could suggest how to merge a date formatted as above, and a time column formatted as character 04:46:56pm and output as a datetime integer. That's really where I'm going with this.
08-05-2013 09:18 AM
okay... answered my own question and got what I was ultimately looking for by cobbling together some things I found. I do work better on a Monday morning over a Friday afternoon.
sas_DT = (datevariable * 24 * 60 * 60) + input(timevariable, time10.); /* datevariable is recognized by SAS as a date variable, timevariable is a character*/
format sas_DT datetime.;
Interestingly, by figuring this out I realized that I really dont't need to remember some formatting command I won't use very often, but instead just include the variable in a function and it will return as an integer
datevariabe_2 = datevariable + 1 - 1;
and sure enough... it output it as the integer I was after.
by the by can anyone tell me why the information on this page doesn't work?
I have SAS 9.2, but it balked when I originally tried to use timeampmw.d
08-05-2013 09:25 AM
Your link is to a FORMAT and not an INFORMAT. Is that your question?
The DHMS() function is useful for converting separate date and time values into a date time value.
dt = dhms(today(),0,0,time());
put dt datetime.;
08-05-2013 05:03 PM
To show a SAS date as the integer value, simply refer to the date value without applying any formatting. Example:
data some_dates ;
input mydate :mmddyy10.;
integer_dt = mydate ;
Note re: why the TIMEAMPM format isn't working for you. The TIMEAMPM format only works with SAS TIME and DATETIME values.