BookmarkSubscribeRSS Feed
Pritish
Quartz | Level 8
Hi All,

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 ?

Thanks for your support.
8 REPLIES 8
RickM
Fluorite | Level 6
It looks like PROCESS_DT and PROCESS_TIME are character variables (given the leading zeros). Do you want the result to be a SAS date/time variable or a character variable?
Pritish
Quartz | Level 8
Hey Rick:

No they don't have a character variable. I gave the example which I think created the confusion. They are in numeric format.

I want it to store Process_Dt in Date format and Process_Time in Time format in SAS.
RickM
Fluorite | Level 6
Would Process_Dt still have leading zeros for day of the month? For example Jan. 9th 2011 would be 10911 or would it be 1911?
Pritish
Quartz | Level 8
Well, that's a good question Rick.

I have both sort of values in my txt file. ex: 010911 and 100110

The date in the txt file are 6 digits in length.
RickM
Fluorite | Level 6
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).

Good luck!
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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:

DATA _NULL_;
FORMAT MYDATE YYMMDDS10.;
MYDATE = INPUT(PUT(010111,Z6.),ANYDTDTE.);
PUT MYDATE= ;
RUN;

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.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

sas dates introduction site:sas.com
Pritish
Quartz | Level 8
Hi Sbb,

Thanks for your reply. It was really helpful. For the Process_Time I did something like this:

DATA _NULL_;
FORMAT MYTIME TIME9.;
YY = PUT(00,Z2.);
MYTIME = INPUT(PUT(0820,Z4.)||YY, ND8601TM10.);
PUT MYTIME=;
PUT _ALL_;
RUN;

The reason why I am concatenating 00 is b'coz i just have "1820" or "0820" in my text file.

Do let me know if you have better way of doing it.

Thanks again.

@ Everyone: Thanks for checking out and helping me. Really appreciate your time.
Ksharp
Super User
I am afraid you need to make a delimiter between hour and minute to let sas know it is time.
[pre]
data temp;
input date : mmddyy6. char_time : $6.;
time=input(catx(':',substr(char_time,1,2),substr(char_time,3,2)),time.) ;
format date mmddyy10. time timeampm.;
drop char_time;
cards;
010911 1720
020310 0820
;
run;
[/pre]

Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 901 views
  • 0 likes
  • 4 in conversation