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 (August 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 15 Aug 2006 13:41:37 -0500
Reply-To:     "data _null_;" <datanull@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "data _null_;" <datanull@GMAIL.COM>
Subject:      Re: Reading date-time
Comments: To: "Howard Schreier <hs AT dc-sug DOT org>" <nospam@howles.com>
In-Reply-To:  <200608150015.k7EKs70L019637@mailgw.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 8/14/06, Howard Schreier <hs AT dc-sug DOT org> <nospam@howles.com> wrote: > On Sun, 13 Aug 2006 13:54:16 -0500, data _null_; <datanull@GMAIL.COM> wrote: > > >One could just let the input statement do most of the work. Then you > >don't have to do all that scanning and concatenating. > > > >Data work.dtm; > > Infile Cards dsd; > > input var1:$20. date mmddyy8. time:time10. var3 &$20.; > > datetime = dhms(date,0,0,time); > > format date date7. time time. datetime datetime.; > > list; > > Cards; > >111111111111111,3/12/06 4:21 AM,mango juice > >111111111111111,12/22/06 4:21 pM,mango juice > >;;;; > > Run; > >proc print; > > run; > > Fails with a 6-character date field (eg, 3/2/06). > > Vijay implied that the time of day was not needed. In that case, it can be > handled by INFILE and INPUT thusly, with no post-processing: > > Data work.dtm; > Infile Cards dsd dlm=', '; > input var1:$20. date:mmddyy8. @',' var3 &$20.; > format date date7.; > list; > Cards; > 111111111111111,3/2/06 4:21 AM,mango juice > 111111111111111,3/12/06 4:21 AM,mango juice > 111111111111111,12/22/06 4:21 pM,mango juice > ;;;; >

Schreier's solution fails with field following var3.

Data work.dtm; Infile Cards dsd dlm=', '; input var1:$20. date:mmddyy8. @',' var3 $20. var4; format date date7.; list; Cards; 111111111111111,3/2/06 4:21 AM,mango juice,12 111111111111111,3/12/06 4:21 AM,mango juice,13 111111111111111,12/22/06 4:21 pM,mango juice,14 ;;;; run; proc print; run;

Obs var1 date var3 var4

1 111111111111111 02MAR06 mango juice,12 . 2 111111111111111 12MAR06 mango juice,13 . 3 111111111111111 22DEC06 mango juice,14 .

The following solution I sent to Vijay yesterday when he showed me the error of my ways seems about the easiest to me. No need to ignore time as I see it.

Data work.dtm; Infile Cards dsd; informat var1-var3 $20.; input var1-var3 var4; i = indexc(var2,' '); date = inputn(var2,'mmddyy',i-1); time = input(substr(var2,i+1),time.); datetime = dhms(date,0,0,time); format date date7. time time. datetime datetime.; list; Cards; 111111111111111,3/2/06 4:21 AM,mango juice,12 111111111111111,3/12/06 4:21 AM,mango juice,13 111111111111111,12/22/06 4:21 pM,mango juice,14 ;;;; run; proc print; run;


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