|Date: ||Fri, 12 Sep 2003 20:35:04 +0100|
|Reply-To: ||Crawford <PeterDOTCrawfordATblueyonder.co.uk@Peter.BITNET>|
|Sender: ||"SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>|
|From: ||Crawford <PeterDOTCrawfordATblueyonder.co.uk@Peter.BITNET>|
|Organization: ||blueyonder (post doesn't reflect views of blueyonder)|
|Subject: ||Re: reading from hierarchical files without datatype identifier|
To avoid a step joining to datasets, you could just do the
two infiles in one step... like
%let file =
filename solve1 "&file" lrecl =3000;
filename solve2 "&file" lrecl =3000;
data new_lmps_0( label="read from &file" );
infile solve1 firstobs=4 ;
input @37 udscaseid $19.
// @38 lmpcaseid $16. ;
do until( eof );
infile solve2 firstobs=1 ;
input @1 datatype $1. @72 PNODE_TYPE $1. @;
if datatype="D" and PNODE_TYPE in ("H" "I" "Z")
input @29 date date11.
@41 time time5.
@48 pnode_name $15.
@80 lmp 9.2
@118 loss 8.2
@127 cong 8.2 ;
format date date. time time.;
end /* handling datatype D*/ ;
end /* handling a record from SOLVED2 */ ;
stop; /* end of file on solved2 */
instead of 2 data steps to read the data, I used 2 infile
This provides 2 streams of data in the data step.
Rather than have to bypass handling the SOLVE1 file on all
data step iterations after the first, I put a
do until( eof );
loop around the reading of data from SOLVE2
It doesn't add a lot. Just the "end=eof" on the infile,
an output statement, and a stop statement to avoid having
the data step iterate a second time.
welcome to the wonderful data step
Crawford Software Consultancy Limited
"Sarah Whittier" <swhittier@ISO-NE.COM> wrote in message
> I have a problem related to reading data from flat files into SAS. I am
> using Windows, and the files are text files. The files are essentially
> hierarchical files, however, the rows with the header data that I want are
> not easily identified (i.e., they don't have a consistent datatype
> I want to read certain key values from the 4th and 6th rows of the file
> have these values on each row of the data values in the output SAS
> dataset. I can achieve this by using two data steps with input
> and then a third to set them together. I would prefer to do this in just
> one data step, which I hope will make it easier to set up a program to
> in the 30 or so files that I have. Does anyone have a suggestion for
> modifying the program below to use just one data step? I hope this is
> sufficiently clear without including data.
> filename solved "c:\lmp\data\finalize\MSS_7020030728205502_0X.0_28-JUL-
> data new_lmps_id;
> infile solved firstobs=4 obs=6;
> input @37 udscaseid $19.
> // @38 lmpcaseid $16. ;
> data new_lmps;
> infile solved;
> input @1 datatype $1. @72 PNODE_TYPE $1. @;
> if datatype="D" and PNODE_TYPE in ("H" "I" "Z") then do;
> input @29 date date11.
> @41 time time5.
> @48 pnode_name $15.
> @80 lmp 9.2
> @118 loss 8.2
> @127 cong 8.2 ;
> format date date. time time.;
> data new_lmps_2;
> set new_lmps;
> if _n_ = 1 then set new_lmps_id;
> Thank you,
> Sarah Whittier