| Date: | Sun, 14 Oct 2007 20:17:49 +0000 |
| Reply-To: | iw1junk@COMCAST.NET |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Ian Whitlock <iw1junk@COMCAST.NET> |
| Subject: | Re: no data created??? file out filevar= |
|
Summary: Be careful with MISSOVER and other potential problems
#iw-value=1
Howard gave a model that works with the correct cards data, and
suggested:
Notice the additional INFILE statement, so that SAS always knows
where it is expected to read next.
Notice the additional INPUT statement inside the DO loop.
Notice that there is no need for FILEVAR= on the output side.
The second suggestion is essential.
The first doesn't hurt, but it is not necessary, since the default for
INPUT is DATALINES. It might be considered good protection from
having someone put another INFILE statement at the top of the step,
although I wouldn't bother in this case.
The third, while true, is not the problem, although the original FILE
statement could cause trouble, when the program is run a second time
without deleting the previous output since the MOD option was
specified.
Even if the additional INPUT statement, inside the loop, had been
present, there is still a potential problem depending on how that
missing INPUT statement is written. MISSOVER is an ancient option.
It means - if the record is shorter than specified set the
affected variables to missing.
Here is my test.
1 DATA tmp;
2 LENGTH LINE $ 108 FILELOC $ 128 NEWDATE $ 8;
3 FORMAT LINE $108. INLINE $VARYING128.;
4 INPUT FILELOC $;
5 INFILE dat filevar=FILELOC MISSOVER LENGTH=LINELEN
6 COLUMN=COL end=done;
7
8 DO WHILE (NOT DONE);
9 input line $108. ;
10 food='c:\junk\0124001.01';
11 FILE OUT filevar=food MOD;
12 PUT LINE $108.;
13 putlog ">>>" line ;
14 end;
15
16 DATALINES;
NOTE: Variable NEWDATE is uninitialized.
NOTE: Variable INLINE is uninitialized.
NOTE: The infile DAT is:
File Name=c:\junk\food1xxx.DAT,
RECFM=V,LRECL=256
NOTE: The file OUT is:
File Name=c:\junk\0124001.01,
RECFM=V,LRECL=256
>>>
>>>
NOTE: The infile DAT is:
File Name=c:\junk\food2vvvv.DAT,
RECFM=V,LRECL=256
>>>
>>>
NOTE: 2 records were read from the infile DAT.
The minimum record length was 1.
The maximum record length was 1.
NOTE: 2 records were read from the infile DAT.
The minimum record length was 1.
The maximum record length was 1.
NOTE: 4 records were written to the file OUT.
The minimum record length was 108.
The maximum record length was 108.
NOTE: The data set WORK.TMP has 2 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.08 seconds
cpu time 0.02 seconds
19 ;
Note that LINE is set to blanks because of MISSOVER. I used the
format, $128., but the result would be the same with the preferred,
$CHAR128. It would be wiser to use the contemporary option,
TRUNCOVER, which says accept what you can get without going to the
next line.
Finally note that while 4 blank lines were written to the external
file, there are only 2 in TMP. This is because an explicit OUTPUT is
needed for the SAS data set when writing in a loop.
In answer to Howard's question:
One thing that I don't quite understand: How come it is not
necessary to reinitialize DONE to 0 somewhere outside the DO loop?
The DAT INFILE statement resets DONE since a new file is given.
Perhaps you are thinking of something like
data w ;
x = 2 ;
run ;
data q ;
do while (not done) ;
set w end = done ;
output ;
end ;
if _n_ > 1 ;
done = 0 ;
do while (not done) ;
set w end = done ;
output ;
end ;
run ;
In this case the resetting of DONE is essential.
Ian Whitlock
==============
Date: Sun, 14 Oct 2007 11:51:08 -0400
Reply-To: "Howard Schreier <hs AT dc-sug DOT org>"
<nospam@HOWLES.COM>
Sender: "SAS(r) Discussion"
From: "Howard Schreier <hs AT dc-sug DOT org>"
<nospam@HOWLES.COM>
Subject: Re: no data created??? file out filevar=
On Fri, 12 Oct 2007 11:48:05 -0700, adac1121@GMAIL.COM wrote:
>DATA tmp;
>LENGTH LINE $ 108 FILELOC $ 128
> NEWDATE $ 8;
> FORMAT LINE $108. INLINE $VARYING128.;
> INPUT FILELOC $;
> INFILE dat filevar=FILELOC MISSOVER LENGTH=LINELEN
>
>COLUMN=COL end=done;
>
>DO WHILE (NOT DONE);
>
>food='/xxxx/0124001.01';
>
>FILE OUT filevar=food MOD;
> PUT LINE $108.;
>
>end;
>
>DATALINES;
>/food1xxx.DAT
>/food2vvvv.DAT
>
>I have no data for the output????
>
>I can't find any reference for dat and out after the infile and file
>statement??? can we use any name before filevar=???
>
>Thanks,
Here's a simplified model of what I think is wanted.
First, generate some test input:
data _null_;
file 'food1xxx.DAT';
put 'a' /'b';
file 'food2vvvv.DAT';
put 'c' /'d';
run;
The task I believe is to concatenate a series of specified files into
one
all-inclusive file. Here's the code:
DATA _null_;
infile datalines;
INPUT FILELOC $;
INFILE dat filevar=FILELOC end=done;
FILE 'xxxx-0124001.01';
DO WHILE (NOT DONE);
input;
PUT _infile_;
end;
DATALINES;
one
two
;
Notice the additional INFILE statement, so that SAS always knows where
it is
expected to read next.
Notice the additional INPUT statement inside the DO loop.
Notice that there is no need for FILEVAR= on the output side.
Check the output:
data _null_;
infile 'xxxx-0124001.01';
input;
put '>>> ' _infile_;
run;
Log shows:
>>> a
>>> b
>>> c
>>> d
One thing that I don't quite understand: How come it is not necessary
to
reinitialize DONE to 0 somewhere outside the DO loop?
|