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 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 15 Jun 2007 11:39:17 +0200
Reply-To:     SAS-L List <sas-l@listserv.uga.edu>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Robert Bardos <bardos2@ANSYS.CH>
Subject:      Re: how to import one txt file?
In-Reply-To:  <002101c7ae96$aa277af0$bd00a8c0@adriano>
Content-Type: text/plain; charset="iso-8859-1"

Adriano,

Pointer to Adriano's post in SAS-L's archive: http://tinyurl.com/2qmuoa

it seems you want to read the content of emails that were generated by people filling in some kind of form. Off the top of my head I see two approaches

Approach one which relies on all emails having the exactly same number and layout of lines [*1] would use an input statement covering an exact number of lines somewhat like

input #1 @'From:' .... #2 @'Date:' .... #3 @'To:' .... ... ;

etc.

[*1] When using relative line numbers like #1, #2, #3 I'm assuming that your original message was not interspersed with all those empty lines. If the empty lines are part of your data, you will have to adjust the line numbers accordingly. Anyway: do take your time to study the powerful INPUT statement!

Approach two would read line by line, identify the 'record type', parse it accordingly and write out an observation when an email boundary is reached. Somewhat like

data ...; /* <-- data step begins here */ infile ...; input @; word_one = scan(_infile_,1,' '); select (word_one); when ('From:' ) link parse_from ; when ('Date:' ) link parse_date ; ... when ('1' ) link process_question1 ; when ('2' ) link process_question2 ; ... otherwise ... end; return;

parse_date: input @'Date:' date_string $char40. ; /* more logic here */ return;

parse_from; /* potential place for boundary logic */ input @'From:' from_string $char100. ; /* more logic here */ return;

process_question1: input #2 answer1 $8. ; /* more logic here */ return;

process_question2: input #2 answer2 $8. ; /* more logic here */ return;

run; /* <-- data step ends here */

Adriano, all of this is untested and intended to give you an idea only. There will be lots of problems that you encounter when trying to parse your files. Tackle the problems one by one and try to understand the various ERROR and NOTE messages that will most certainly show up. Seems like a good learning exercise.

Kind regards

Robert Bardos Ansys AG, Zurich, Switzerland

> -----Urspruengliche Nachricht----- > Adriano Rodrigues - Instituto GPP > Gesendet: Donnerstag, 14. Juni 2007 17:14 > > Hi all, > > I have to import one file received from emails with > this layout (here only 2 emails, but file have 5000+): > > Basically after all “:” I have data and after “?” also, > only in time “:” is not true. > > Thanks in advance, > > Adriano > Rest snipped as URL to original post has been provided above / rb.


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