Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing multiple output files 2

Status
Not open for further replies.

burndengreen

Programmer
Jan 28, 2004
6
0
0
GB
I am reading an input file with in excess of 125,00 recs, (and increasing all the time). I want to break it down into SAS output tables with 15,000 recs on each with the remainder on the final file. I have to keep changing my code to accomodate the increasing number of files. Is there any way to write the first 15000 recs to a file called say
TESTIT1 the second file to TESTIT2 etc. with the names being allocated on the fly, i tried . I have tried using macros but SAS seems to process macros before other code so the names never change.
y + 1;
filnam = 'TESTIT';
thisfile = compress(trim(filnam)||trim(y));
call symput ('thisfil',thisfile);
I also executed the above code every time _N_ was divisible by 15000 and used

data work.&thisfil ;

as my output file definition but it wrote everything to TESTIT1.

This is driving me bonkers now any help greatly appreciated.
 
Burndengreen,
What you need is a good macro. (One that is dynamic and will change with the increase of records.)

There are several ways to accomplish your task. Let me map out the logic before I give you code examples.
1) You need to know the amount of records in your sas ds (dataset).
2) Have the macro reiterate the 'set' statement total/15000= times.
3) Have the macro change the name of the ds with some rules.

OK now for the code:
%macro output1(libnm=,dsname=);
data _null_;
set sashelp.vtable end=last;
max_loop=ceil(nobs/15000);

where trim(upcase(libname))="&libnm" and
trim(Upcase(memname))="&dsname";
if last then
call symput("YOURLOOP",trim(left(put(max_loop,8.))) );
run;

%do i=1 %to &yourloop;
data outds&i;
set &libnm..&dsname (firstobs=%eval( (((&i-1)*15000)+1)) obs=%eval(&i*15000) );
run;
%end;
%mend;
***TESTED WITH A DS NAMED WORK.TEST2 ****;
%output1(libnm=WORK,dsname=TEST2);

I hope that this example helps you.
klaz
 
Cheers Klaz

Fantastic solution, you truly are a prince amongst men (or women).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top