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 (August 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 28 Aug 2007 10:35:11 -0500
Reply-To:     "data _null_;" <datanull@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "data _null_;" <datanull@GMAIL.COM>
Subject:      Re: external file help
Comments: To: boulmo <pierre.coste@gmail.com>
In-Reply-To:  <1188288772.613203.247490@19g2000hsx.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1

Many programs have been written to solve this problem in the last 25 or so years.

I was thinking that filevar and sharebuffers might be useful for this problem. I had not tried that and thought it might be interesting.

The following program places a string in the titles then a data step is used to search for and replaced 'Page n of p' with the actual n and p values "filled in".

Naming the output is up to you. Usually some code is written to determine the name of the currently executing SAS program and that name is used to create the output file.

options nodate nonumber;

%let ls=%sysfunc(getoption(ls)); title1 "%sysfunc(right(%qsysfunc(putC(Page n of p,$&ls.))))"; /*something to look for*/ title2 'Appendix 14.1.2.1'; title3 'Zip codes';

filename ft33f001 'Pageof.LISTING'; /*output file*/

/*Necesssary evil. I could not read a file twice without first */ /*opening another. This could be "any" file that EXISTS. But needs*/ /*just one record.*/ filename ft15f001 temp; /*needed to prevent ERROR: File is in use,*/ parmcards;

;;;;

ods listing file=ft33f001; /*make some output*/ proc print data=sashelp.zipcode(obs=500); run; ods listing;

libname pgmlib '.'; /*make it a stored complied program then you can call it with a two statement data step, or wrap it up the %macro etc.*/ data _null_ / pgm=pgmlib.pageof; attrib file length=$256; do file=pathname('ft33f001'),pathname('ft15f001'); do until(eof); infile dummy filevar=file end=eof; input; if index(_infile_,'Page n of p') then _page0_ + 1; end; end; do file=pathname('ft33f001'); do until(eof); infile dummy filevar=file end=eof sharebuffers length=lineLength; file dummy filevar=file; input; if index(_infile_,'Page n of p') then do; attrib _string_ length=$20; _page_ + 1; _string_ = catx(' ','Page ',_page_,'of',_page0_); substr(_infile_,1+lineLength-length(_string_),length(_string_))=_string_; put; end; end; end; stop; run;

/*call it*/ data pgm=pgmlib.pageof; execute; run;

On 8/28/07, boulmo <pierre.coste@gmail.com> wrote: > A friend needs some help > > here is the thing : > > we need to put the number of page of an external file. the first line > of each page starts by : > > Appendix > 14.2.2.2.2 / > 1 > > and we want > > Appendix > 14.2.2.2.2 > 1/20 > > what has been done : > > data WORK.TOTO ; > %let _EFIERR_ = 0; /* set the ERROR detection macro variable */ > infile 'C:\temp\a1422.txt' delimiter='09'x MISSOVER DSD > lrecl=32767; > informat VAR1 $133. ; > format VAR1 $133. ; > input > VAR1 $ > ; > > if _ERROR_ then call symput('_EFIERR_',1); /* set ERROR detection > macro variable */ > length nbline 8.; > nbline=_N_; > run; > > proc sql noprint; > select count(distinct(nbline)) > into :nbline > from work.toto; > %let nbpage=%eval(&nbline/40); > quit; > > %macro print_page; > > data re; > %let _EFIERR_ = 0; /* set the ERROR detection macro variable */ > infile 'C:\temp\a1422.txt' delimiter='09'x scanover DSD > lrecl=32767 sharebuffers; > informat VAR1 $133. ; > format VAR1 $133. ; > input VAR1 $ > ; > run; > if _ERROR_ then call symput('_EFIERR_',1); /* set ERROR detection > macro variable */ > > %do i=1 %to &nbpage; > %if &i=1 %then %do ; > file 'C:\temp\a1422.txt'_N_=40 _FILE_=VAR1; > if substr(VAR1,1,12)="Appendix 14." then > put #1 var1 + (-1) "/&nbpage"; > stop; > %end; > %else %do; > file 'C:\temp\a1422.txt'_N_=40 _FILE_=VAR1; > if substr(VAR1,1,12)="Appendix 14." then > put var1 + (-1) "/&nbpage"; > stop; > %end; > %end; > > run; > > %mend; > > %print_page; > > and what happens : > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > Appendix 14.2.2.2.2 Protocol > deviations > 1/18 > > > > > 18 times... > > someone would have an idea >


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