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?
Thank you
try this
data required;
set yourSASdatasetname;
newdate=input(substr(strip(olddate),1,10),mmddyy10.);
run;
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.
data _null_;
set MYDATA ;
put datevar= / datevar= best12. / datevar=date9. ;
run;
If it is a date then you will get something like this:
datevar=06/04/13
datevar=19513
datevar=04JUN2013
If it is character you will get
NOTE 484-185: Format $DATE was not found or could not be loaded.
datevar=06/04/13
datevar=06/04/13
datevar=06/04/13
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.
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.
data a;
set b;
sas_DT = (datevariable * 24 * 60 * 60) + input(timevariable, time10.); /* datevariable is recognized by SAS as a date variable, timevariable is a character*/
proc print;
format sas_DT datetime.;
run;
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
e.g.
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?
SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition
I have SAS 9.2, but it balked when I originally tried to use timeampmw.d
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.
data _null_;
dt = dhms(today(),0,0,time());
put dt datetime.;
run;
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 ;
datalines;
1/1/2001
2/2/2002
3/3/2003
4/4/2004
5/5/2005
6/30/2006
;
;;;;
Note re: why the TIMEAMPM format isn't working for you. The TIMEAMPM format only works with SAS TIME and DATETIME values.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.