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 (July 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 13 Jul 2004 16:04:05 -0400
Reply-To:     Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Subject:      Re: HELP: A weird Data step issue

With assurance that ID never contains embedded blanks, I might omit the DSD option, treat both the comma and the blank as delimiters, and let the INPUT statement load numeric date and time variables. So the code would become:

data whats_wanted( keep= id timestamp n1 n2 ); informat id $15. date mmddyy10. time time.; format timestamp datetime20.; infile cards dlm=' ,' truncover ; input id date time n1 n2 ; timestamp = dhms(date,0,0,time); if _n_ < 10 then put _all_ ; cards;

On Tue, 13 Jul 2004 04:26:25 -0400, Peter Crawford <peter.crawford@BLUEYONDER.CO.UK> wrote:

>On Tue, 13 Jul 2004 03:10:02 -0400, Vijay Mehrotra <vjm@SFSU.EDU> wrote: > >>As requested, here are additional details on the Data Step problem. The >>raw data looks like this: >> >>SAMPLE RECORDS >>4032221.4209832,1/2/2003 4:00,32,545 >>ad49503.fd45092,12/21/2002 11:45,43,678 >> >>FIELD DESCRIPTION >>The first field is a character of fixed length 15 >> >>The second field is the composite of two fields (a date and a military >>time), and so the length of this field ranges from 13 to 16 characters >> >>The third and fourth fields are numeric >> >>SAS DATA STEP CODE >>The first thing I tried: >> >>data work.datfile; >> infile='filename' delimiter=','; >> input ID $ 1-15 @; >> input DateVar $ @; >> input Num1 Num2; >>run; >> >>The thought was to read in the Date+Time composite field into DateVar, and >>then parse it on a subsequent Data Step. >> >>However, the ID, Num1, and Num2 fields all read in fine, but the DateVar >>read in only the first 8 characters of the date >> >>Next, I managed to get the Date part of the Date+Time composite field into >>DateVar, but got none of the Time field at all: >> >>data work.datfile; >> infile='filename' delimiter=','; >> input ID $ 1-15 @; >> input DateVar : mmddyy10. @; >> input Num1 Num2; >>run; >> >>From here, I tried a bunch of other things and read a bunch of help notes >>on the SAS site, but still did not manage a solution by which I managed to >>enter both parts of the Date+Time field, either into a single field in a >>SAS dataset or into multiple fields. >> >>Again, any ideas on this are welcomed - perhaps there is something obvious >>that I've just overlooked - and thanks in advance for your help. >> >>Regards, >> >>Vijay > >Hi Vijay > >CSV is such a standard that SI can offer a strong solution for handling it. >I refer to this solution as the DSD method. >DSD is an infile option. It seems designed for your data. >With this option, data is passed to the input statement, to be >parsed by informats, in the strings that lie between each delimiter. >These delimiters are the second layer. The first is the "line endings". >Because the delimiters take this high level of importance, the informat >lengths must be taken very carefully. On an input statement, a >length given on an informat would override the DSD effect. Of course, >by adding another option the problems can be overcome, but taking >things out, I find simplify the issue. >That is why I reccommended using no informats on the input >statement, but puting them on their own statement. But....... >enough (too many?) words.... here is log testing the code for cards >4032221.4209832,1/2/2003 4:00,32,545 >ad49503.fd45092,12/21/2002 11:45,43,678 > > >148 data whats_wanted( keep= id timestamp n1 n2 ); >149 informat id $15. timestam $20. ; >150 format timestamp datetime20. ; >151 infile cards dsd truncover ; >152 input id timestam n1 n2 ; >153 timestamp = dhms( input(timestam, mmddyy10.) >154 , 0,0 >155 , input( scan( timestam, 2,' '), time. ) >156 ) ; >157 if _n_ < 10 then put _all_ ; >158 cards; > >id=4032221.4209832 timestam=1/2/2003 4:00 timestamp=02JAN2003:04:00:00 >n1=32 n2=545 _ERROR_=0 _N_=1 >id=ad49503.fd45092 timestam=12/21/2002 11:45 timestamp=21DEC2002:11:45:00 >n1=43 n2=678 _ERROR_=0 _N_=2 >NOTE: The data set WORK.WHATS_WANTED has 2 observations and 4 variables. > >*unfortunately, SAS9.1 informat anydtdtm. doesn't support your > timestamp, so I had to load it as a string and parse it > separately; > >Hopefully this will give an approach you can use > >Regards >Peter Crawford


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