General form, INFILE
statement with the FILEVAR= option:
INFILE file-specification FILEVAR= variable;
FILEVAR= variable
names a variable whose
change in value causes the INFILE statement to close the current input
file and open a new input file.
variable
contains a character
string that is a physical filename.
|
data work.quarter;
infile temp filevar=nextfile;
input Flight $ Origin $ Dest $
Date : date9. RevCargo : comma15.;
----+----10---+----20---+----30---+----40 IA10200 SYD HKG 01SEP2000 $189,441.00 IA10201 SYD HKG 01SEP2000 $175,473.00 IA10300 SYD CBR 01SEP2000 $1,370.00 IA10301 SYD CBR 01SEP2000 $710.00 IA10302 SYD CBR 01SEP2000 $1,210.00 |
----+----10---+----20---+----30---+----40 IA10200 SYD HKG 01OCT2000 $182,457.00 IA10201 SYD HKG 01OCT2000 $160,923.00 IA10300 SYD CBR 01OCT2000 $1,030.00 IA10301 SYD CBR 01OCT2000 $870.00 IA10302 SYD CBR 01OCT2000 $770.00 |
----+----10---+----20---+----30---+----40 IA10200 SYD HKG 01NOV2000 $176,637.00 IA10201 SYD HKG 01NOV2000 $164,997.00 IA10300 SYD CBR 01NOV2000 $1,230.00 IA10301 SYD CBR 01NOV2000 $1,230.00 IA10302 SYD CBR 01NOV2000 $790.00 |
data work.quarter;
infile temp filevar=nextfile;
input Flight $ Origin $ Dest $
Date : date9. RevCargo : comma15.;
Month
is then
concatenated with the text string .dat. data work.quarter; do Month = 9, 10, 11; nextfile="c:sasusermonth" !!put(Month,2.)!!".dat"; infile temp filevar=nextfile; input Flight $ Origin $ Dest $ Date : date9. RevCargo : comma15.; end;
General form, COMPRESS
function:
COMPRESS(source, <characters-to-remove>);
source
specifies a source
string that contains the characters to remove.
characters-to-remove
specifies the character
or characters that SAS removes from the source string.
|
data work.quarter;
do Month = 9, 10, 11;
nextfile="c:sasusermonth"!!put(Month,2.)!!".dat";
nextfile=compress (nextfile,' '),
infile temp filevar=nextfile;
input Flight $ Origin $ Dest $
Date : date9. RevCargo : comma15.;
end;
data work.quarter;
do Month = 9, 10, 11;
nextfile="c:sasusermonth"!!compress(put(Month,2.)!!".dat",' '),
infile temp filevar=nextfile;
input Flight $ Origin $ Dest $
Date : date9. RevCargo : comma15.;
end;
data work.quarter; do Month = 9, 10, 11; nextfile="c:sasusermonth" !!compress(put(Month,2.)!!".dat",' '), infile temp filevar=nextfile; input Flight $ Origin $ Dest $ Date : date9. RevCargo : comma15.; output; end; stop;
General form, INFILE
statement with the END= option:
INFILE file-specification END=variable;
variable
names a variable that
SAS sets to these values:
|
data work.quarter; do Month = 9, 10, 11; nextfile="c:sasusermonth" !!compress(put(Month,2.)!!".dat",' '), do until (lastobs); infile temp filevar=nextfile end=lastobs; input Flight $ Origin $ Dest $ Date : date9. RevCargo : comma15.; output; end; end; stop; run;
data work.quarter (drop=monthnum midmon lastmon); monthnum=month(today()); midmon=monthnum-1; lastmon=midmon-1; do Month = monthnum, midmon, lastmon; nextfile="c:sasusermonth" !!compress(put(Month,2.)!!".dat",' '), do until (lastobs); infile temp filevar=nextfile end=lastobs; input Flight $ Origin $ Dest $ Date : date9. RevCargo : comma15.; output; end; end; stop; run;
1
and 0
respectively.
Since there is no “0” month, the program would fail
to read the third raw data file.
data work.quarter (drop=monthnum midmon lastmon); thisday=today(); monthnum=month(thisday); midmon=month(intnx('month',thisday,-1)); lastmon=month(intnx('month',thisday,-2)); do Month = monthnum, midmon, lastmon; nextfile="c:sasusermonth" !!compress(put(Month,2.)!!".dat",' '), do until (lastobs); infile temp filevar=nextfile end=lastobs; input Flight $ Origin $ Dest $ Date : date9. RevCargo : comma15.; output; end; end; stop; run; |
|
12
to
Midmon and a value of 11
to
Lastmon.
data work.quarter (drop=monthnum midmon lastmon); monthnum=month(today()); midmon=month(intnx('month',today(),-1)); lastmon=month(intnx('month',today(),-2)); do Month = monthnum, midmon, lastmon; nextfile="c:sasmonth"!!compress(put(Month,2.)!!".dat",' '), do until (lastobs); infile temp filevar=nextfile end=lastobs; input Flight $ Origin $ Dest $ Date : date9. RevCargo : comma15.; output; end; end; stop; run; |
|