LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2008, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 10 Jun 2008 17:26:19 -0500
Reply-To:   Mary <mlhoward@avalon.net>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Mary <mlhoward@AVALON.NET>
Subject:   Re: Getting Data out of a string and combining it to create a datetime12. variable
Comments:   To: "Kevin F. Spratt" <Kevin.F.Spratt@DARTMOUTH.EDU>
Content-Type:   text/plain; charset="iso-8859-1"

Kevin,

Here's another way to get the data isolated- I'm still pondering data _null_'s solution as I don't quite understand how it works. Data _null_, could you provide an example of the _infile_ option you were talking about?

I'm also not sure how to get from here, where I have variables for the dates, to datetime values. Could anyone help with that part?

-Mary

data test;

informat longstring1 $50. longstring2 $50. datetime1a datetime18.;

longstring1="Created at 5/14/2008 10:43 AM˙ byRaterA˙Last";

longstring2="modified at 5/14/2008 11:44 AM˙ byRaterA˙";

shortstring1=substr(longstring1,12,38);

shortstring2=substr(longstring2,13,37);

date1=substr(shortstring1,1,index(shortstring1,' '));

shortstring1a=substr(shortstring1,index(shortstring1,' '),50-index(shortstring1,' '));

date2=substr(shortstring2,1,index(shortstring2,' '));

shortstring2a=substr(shortstring2,index(shortstring2,' '),50-index(shortstring2,' '));

if index(shortstring1a,'AM')> 0 then

time1=substr(shortstring1a,1,index(shortstring1a,'AM')+ 1);

else if index(shortstring1a,'PM')> 0 then

time1=substr(shortstring1a,1,index(shortstring1a,'PM')+ 1);

if index(shortstring2a,'AM')> 0 then

time2=substr(shortstring2a,1,index(shortstring2a,'AM')+ 1);

else if index(shortstring2a,'PM')> 0 then

time2=substr(shortstring2a,1,index(shortstring2a,'PM')+ 1);

run;

----- Original Message ----- From: Kevin F. Spratt To: SAS-L@LISTSERV.UGA.EDU Sent: Tuesday, June 10, 2008 3:55 PM Subject: Getting Data out of a string and combining it to create a datetime12. variable

I have a variable that is a text field. I include a case below:

*******************************************************************************************

Created at 5/14/2008 10:43 AM˙ byRaterA˙Last modified at 5/14/2008 11:44 AM˙ byRaterA˙

*******************************************************************************************

I would like to convert this field into two datetime fields

one reflecting 5/14/2008 10:43 AM and the other reflecting 5/14/2008 11.43 AM.

Although I don't have much data in the system as yet, I am assuming that the spacing (i.e., how many spaces until the first 5/14/2008 and the 10:43 AM and the spacing to the 2nd 5/14/2008 and the 11:44 AM) will not be consistent.

Thus, my simple minded approach using the substr function will not work.

After isolating these two dates and times, I am also unclear how to combine these date and time values to create a datetime12 variable.

I'm running SAS 9.1.3 in the Windows XP environment and, as always, help from the list is greatly appreciated.

______________________________________________________________________

Kevin F. Spratt, Ph.D. Department of Orthopaedic Surgery Dartmouth Medical School One Medical Center Drive DHMC Lebanon, NH USA 03756 (603) 653-6012 (voice) (603) 653-6013 (fax) Kevin.F.Spratt@Dartmouth.Edu (e-mail) _______________________________________________________________________


Back to: Top of message | Previous page | Main SAS-L page