BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
Hi ina a text obs i am having data like this
Time_text
03/08/2009 16:45 date of this
03/08/2009 18:95 new time

In this i want the obs with out the Text like this and it should be minused form the top by below and the output should be in date and time only.

like this : dif

03/08/2009 16:45
03/08/2009 18:50 2.05
1 REPLY 1
Patrick
Opal | Level 21
Use scan() with delimiter BLANK to read the first and second word in the string.

Use a date informat for the first word in the string and assign it to a variable, something like:
MyDate=input(scan(Time_text,1,' '),ddmmyy10.);

Use a time informat for the second word in the string and assign it to a variable (i.e. MyTime).

"it should be minused form the top by below..."
It's not really clear to me if you need the difference to the first obs or just to the previous obs.
It looks for sure like one of this a bit mean (but good) excercises and I'm almost sure that the data you were given has different dates in it. That means that just calculating the difference between the values in the time variable goes wrong when you pass over midnight.

What you can do is: Create a datetime variable by using "word1" and "word2" in the string together with a datetime informat. Assign the datetime value to a variable.
The datetime value can also be created by summing the value in MyTime with the value in MyDate. As MyDate is a date value (=days since 1/1/1960) and a datetime value is in seconds since 1/1/1960 the MyDate value has to be multiplied by the seconds of a day (86400) before summing with MyTime (which should already be a value in seconds).

Then just use the lag() function, i.e. timedif=lag(datetimevar)-datetimevar;
The value you get this way is the difference in seconds. Apply a format (could also be a picture format) or use functions like hour() to present the value in hours and minutes.

HTH
Patrick

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 554 views
  • 0 likes
  • 2 in conversation