Hello,
I am practicing filevar= option. I tried to mock the code in the advanced certification preparation book and the code is as below:
data work.sample;
do number=0,1,2;
nextfile="C:/CT/try/data/sample"!!compress(put(number,2.)!!".txt",'');
infile temp filevar=nextfile end=lastobs;
input ID one $ two $ three $;
output;
end;
stop;
run;
It works well.
Then I am thinking about what will happen if I replace the temp by a fileref, so the code becomes:
filename xyz 'C:/CT/try/data/sample0.txt';
data work.sample3;
do number=1,2;
nextfile="C:/CT/try/data/sample"!!compress(put(number,2.)!!".txt",'');
infile xyz filevar=nextfile end=lastobs;
input ID one $ two $ three $;
output;
end;
stop;
run;
and then I got the following log:
The infile XYZ is:
Filename=C:\CT\try\data\sample1.txt,
RECFM=V,LRECL=32767,File Size (bytes)=706,
Last Modified=15Sep2017:15:13:54,
Create Time=15Sep2017:15:13:54
NOTE: The infile XYZ is:
Filename=C:\CT\try\data\sample2.txt,
RECFM=V,LRECL=32767,File Size (bytes)=220,
Last Modified=15Sep2017:15:14:20,
Create Time=15Sep2017:15:14:20
NOTE: 1 record was read from the infile XYZ.
The minimum record length was 30.
The maximum record length was 30.
NOTE: 1 record was read from the infile XYZ.
The minimum record length was 30.
The maximum record length was 30.
NOTE: The data set WORK.SAMPLE3 has 2 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.07 seconds
cpu time 0.04 seconds
So why does this happen? Is it OK to use a fileref to replace the temp usually?
Thank you!
The file reference in an infile statement with filevar= is just a placeholder.
Thank you! Can I use any placeholder though? I replaced by something casually but I still have the length limit
Log lines like
NOTE: 1 record was read from the infile XYZ.
The minimum record length was 30.
The maximum record length was 30.
is just information about your file. It doesn't signal any problem. Unless, of course, your file has records that aren't 30 characters long.
Ohhhh Ok, thank you!!
When used with filevar, the fileref is just a placeholder, It is ignored.
But there is a maxim record length so I cannot have the same output as the first one.
And can I use any placeholder? I replaced it by something casually but I still have the length limit
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.