Date: Tue, 30 Sep 2003 14:06:09 -0400
Reply-To: "Droogendyk, Harry" <Harry.Droogendyk@CIBC.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Droogendyk, Harry" <Harry.Droogendyk@CIBC.COM>
Subject: Re: Re-Reading same infiles in a Datastep in SAS
Content-Type: text/plain; charset="iso-8859-1"
I don't know that your approach is the most efficient. Can you not sort the
dataset containing reqtype by reqtype and read the template files only once
each on first.reqtype, perhaps by storing the template records in an array?
If not, here's a solution that uses the f* functions to read / rewind an
input file. Perhaps you can adapt it to your application:
filename raw_data "c:\temp\test.txt";
data a ( drop =_: );
length record $80;
_file_handle = fopen('raw_data','i');
put _file_handle=;
times = 1;
_read_rc = fread(_file_handle);
do until(_read_rc);
_get_rc = fget(_file_handle,record,80);
output;
_read_rc = fread(_file_handle);
end;
_rewind_rc = frewind(_file_handle);
times = 2;
_read_rc = fread(_file_handle);
do until(_read_rc);
_get_rc = fget(_file_handle,record,80);
output;
_read_rc = fread(_file_handle);
end;
_rc = fclose(_file_handle);
run;
proc print;run;
-----Original Message-----
From: Harmeet [mailto:hkalra@WEBGABLE.COM]
Sent: September 30, 2003 1:45 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re-Reading same infiles in a Datastep in
SAS
Hello!
I need to write a program in SAS to read different template
files(from
beginning to end) based on the value of a reqtype variable
in my
datastep.
Once I get to the end of the first infile on my first
observation, I
am having difficulty in rereading the same file. I have
tried using
input with line number option e.g: INPUT #L; where I
increment the
value of L after every input and when it gets to the end of
file the
value of L is reset 1.
Also, I do need to to modify some lines read from the
template file(s)
before putting the lines in the outfiles.
Any help in how to handle this will be greatly appreciated.
Please let
me know if macros can be the solution for this or some other
technique.
Thanks ......