I have got a text file which has date & timing which relates to the process starting time and time it took for it to complete. Now I want to maintain all this timing in a table. But the problem that I am facing is with the date and time in a number format. For ex:
1. Process_Dt has a value of 010911 which can be intrepreted as a Jan 9th, 2011. I want to convert this 010911 into 01/09/11 or 01/09/2011 format. I tried something like this:
date = PROCESS_DT;
PUT date = mmddyys10.;
but it didn't work. Can someone provide me some guidance on how can I achieve this?
2. Process_Time: So similar to date the timing in the txt file is like 1720 or 0820 which can be read as 17:20:00 PM or 08:20:00 AM. I am not able to figure how to convert this into time. I tried creating a providing a format of Time9. when I imported the file but all in vain.
This is what I tried for time:
FORMAT PROCESS_TIME TIME9.
It gave me some value like 0:28:40 which obviously doesn't make sense. Can you please provide share your knowledge on how can I convert the time ?
You could do something like month=floor(PROCESS_DT/10000), day=floor(PROCESS_DT/100)-month*100, etc. and then use date=MDY(month,day,year) to get a SAS date. There is a similar function for time, HMS(Hours, Minutes, Seconds).
Using a DATA step technique, take advantage of SAS INPUT function and use the appropriate INFORMAT to convert your numeric data-string (or otherwise a character data-string) into a SAS NUMERIC variable (DATE type) with the desired FORMAT applied for reporting.
If you truly have a SAS numeric variable with mmddyy, then you will need to also use a PUT within the INPUT, such as:
FORMAT MYDATE YYMMDDS10.;
MYDATE = INPUT(PUT(010111,Z6.),ANYDTDTE.);
PUT MYDATE= ;
And, for numeric TIME data-string conversion, do something similar again with INPUT and PUT, using the appropriate INFORMAT.
Suggest you start by reviewing SAS support website technical documentatoin and supplemental reference materials on this topic -- see search argument below.
Suggested Google advanced search argument, this topic / post:
I am afraid you need to make a delimiter between hour and minute to let sas know it is time.
input date : mmddyy6. char_time : $6.;
format date mmddyy10. time timeampm.;