Art
thank you for thinking of me!
Family comes first at christmas and they seem to feel my SAS family should take second place.
Art you were kind to suggest I might have something to offer for a problem like this. However, all possible answers seem to be offered before I catch up with the action!
Perhaps it might open understanding if I describe my interpretation of the problem when there are not enough spaces to reliably use the & modifier (which collapses multiple delimiters as one, only when more than one delimiter is present):
When data positions are not fixed, always predefine (informat) lengths, and the informats where needed - it makes the "input" so much clearer, having just a list of variables.
Seek the reliable rules for parsing - Here these are :
1 there should be a state followed by a zip as the last two things on the third line
2 the prior text is the city name
3 the whole of the second line is the street address
4 assume first and second words of the first line are first and last name (so there won't be middle names nor initials nor titles nor suffix like II/jnr/esq/retd, etcetera)
I have not used the $revers. informat to solve such input problems before but have to recognise that it really does belong in the "_infile_ magic" toolkit!
Without using informat $revers. or PRX my approach would be something like[pre]data Address;
length firstname lastname address $20 city $40 state $2 zip $5;
input firstname lastname ;
input ;
address = _infile_ ;
input @ ;
zip = scan( _infile_, -1 ) ;
call scan( _infile_, -2, POS, LEN ) ;[/pre] * the beginning of the State defines also the end of the city name;
* and call scan() can provide the position for the N-th word
* Here it provides the beginning of the second last word (State) ;[pre] state = substrn( _infile_, pos, len ) ;
city = substrn( _infile_, 1, pos -1 ) ;
cards;
Lee Athnos
1215 Raintree Circle
New York NY 85044
Heidie Baker
1751 Diehl Road
Vienna VA 22124
;[/pre]It is not really "_infile_ magic" as this approach does not modify the _infile_ buffer.
Appropriate respect should go to Søren Lassen for the real "_infile_ magic"!
regards and seasons greetings to all the Forum posters and listeners
peterC