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 (November 2007, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 9 Nov 2007 12:49:50 -0600
Reply-To:     "data _null_," <datanull@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "data _null_," <datanull@GMAIL.COM>
Subject:      Re: input or list question on reading in a text file?
Comments: To: Yu Zhang <zhangyu05@gmail.com>
In-Reply-To:  <7367b4e20711091043l80b0f4v7b88649f8d311c78@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

This technique was proposed by Howard Schreier earlier this year. Can't remember the exact context.

On Nov 9, 2007 12:43 PM, data _null_, <datanull@gmail.com> wrote: > I was thinking the INFILE option EOF would be the solution. > > This is a slightly modified version of one of the previous solutions. > > data test(drop=blankline); > infile cards eof=eof; *<<<< EOF; > input #1 @7 mixedline $16. > #2 allnums1 > #3 allnums2 > #4 @7 nameofcity $12. > #5 allnums3 > #6 allnums4 > #7 @7 bigdate mmddyy10. > #8 allnums5 > #9 @7 mixedline2 $3. > #10 blankline $ 1. > ; > eof: output; *<<< Target of EOF; > format allnums1 z9. allnums2 z6. bigdate mmddyy10.; > cards; > > > > On Nov 9, 2007 12:38 PM, Yu Zhang <zhangyu05@gmail.com> wrote: > > input@1 @; /* -------------------------->new statement,read the infile > > and hold it.*/ > > if compress(_infile_)='' then delete; /*to check if it is a emptyline, > > if so then delete*/ > > else /*else input next 9 lines*/ > > input #1 @7 mixedline $16. > > #2 allnums1 > > #3 allnums2 > > #4 @7 nameofcity $12. > > #5 allnums3 > > #6 allnums4 > > #7 @7 bigdate mmddyy10. > > #8 allnums5 > > #9 @7 mixedline2 $3. > > ; /*the 10 th line is not needed*/ > > > > > > > > HTH > > > > Yu > > > > On Nov 9, 2007 12:24 PM, Jerry L Diebal <jdiebal@gmail.com> wrote: > > > Thanks to everyone who responed. The solutions from Wei, Mary, Michael, and > > > Masuod all seem to work fine except for the problem with the my infile not > > > ending with a blank line. Unless I manually put in a blank line the log > > > shows that i have a "LOST CARD" and the last record is skipped. So the > > > infile is 10 lines for every record but sometimes that last record doesn't > > > have a blank line. Since this will have to be automated and I have no > > > control over the the last line problem does anyone know a workaround so it > > > will work whether or not a blank line ends the file? > > > > > > > > > > > > > > > On 11/8/07, Michael Raithel <michaelraithel@westat.com> wrote: > > > > > > > > Dear SAS-L-ers, > > > > > > > > Jerry L Diebal posted the following: > > > > > > > > > I have a file that has data like what is in the cards datastep below: > > > > > /**********************************/ > > > > > data test; > > > > > input datastuff $ ; > > > > > keep datastuff ; > > > > > cards; > > > > > 111111-911 > > > > > 000111111 > > > > > 000038 > > > > > NAME OF CITY > > > > > 2 > > > > > 0 > > > > > 10/31/2007 > > > > > 28 > > > > > C45 > > > > > > > > > > 222222-911 > > > > > 000222222 > > > > > 000038 > > > > > NAME OF CITY > > > > > 2 > > > > > 0 > > > > > 10/31/2007 > > > > > 28 > > > > > C46 > > > > > > > > > > 333333-911 > > > > > 000333333 > > > > > 000038 > > > > > NAME OF CITY > > > > > 2 > > > > > 0 > > > > > 10/31/2007 > > > > > 28 > > > > > C47 > > > > > ; > > > > > /*********************************************/ > > > > > > > > > > Each record consists of 9 lines like in the sample and each is > > > > > separated by a blank line. The leading zeroes need to be retained on > > > > > any variable starting with a zero. Can someone show me how to turn the > > > > > > > > > above into a dataset? Thanks in advance. > > > > > > > > > > > > > Jerry, > > > > > > > > Check out this TESTED program. It should get you pretty close to where > > > > you need to go! > > > > > > > > data test(drop=blankline); > > > > > > > > input #1 @7 mixedline $16. > > > > #2 allnums1 > > > > #3 allnums2 > > > > #4 @7 nameofcity $12. > > > > #5 allnums3 > > > > #6 allnums4 > > > > #7 @7 bigdate mmddyy10. > > > > #8 allnums5 > > > > #9 @7 mixedline2 $3. > > > > #10 blankline $ 1. > > > > ; > > > > > > > > format allnums1 z9. > > > > allnums2 z6. > > > > bigdate mmddyy10. > > > > ; > > > > > > > > datalines; > > > > 111111-911 > > > > 000111111 > > > > 000038 > > > > NAME OF CITY > > > > 2 > > > > 0 > > > > 10/31/2007 > > > > 28 > > > > C45 > > > > > > > > 222222-911 > > > > 000222222 > > > > 000038 > > > > NAME OF CITY > > > > 2 > > > > 0 > > > > 10/31/2007 > > > > 28 > > > > C46 > > > > > > > > 333333-911 > > > > 000333333 > > > > 000038 > > > > NAME OF CITY > > > > 2 > > > > 0 > > > > 10/31/2007 > > > > 28 > > > > C47 > > > > > > > > ; > > > > run; > > > > > > > > proc print; > > > > run; > > > > > > > > Jerry, best of luck reading that odd data set into SAS! > > > > > > > > I hope that this suggestion proves helpful now, and in the future! > > > > > > > > Of course, all of these opinions and insights are my own, and do not > > > > reflect those of my organization or my associates. All SAS code and/or > > > > methodologies specified in this posting are for illustrative purposes > > > > only and no warranty is stated or implied as to their accuracy or > > > > applicability. People deciding to use information in this posting do so > > > > at their own risk. > > > > > > > > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > > > > Michael A. Raithel > > > > "The man who wrote the book on performance" > > > > E-mail: MichaelRaithel@westat.com > > > > > > > > Author: Tuning SAS Applications in the MVS Environment > > > > > > > > Author: Tuning SAS Applications in the OS/390 and z/OS Environments, > > > > Second Edition > > > > > > > > http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=58172 > > > > > > > > Author: The Complete Guide to SAS Indexes > > > > > > > > http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=60409 > > > > > > > > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > > > > Ice is forming on the tips of my wings > > > > Unheeded warnings. I thought I thought of everything - Pink Floyd > > > > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > > > > > > > > > >


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