DATA Step, Macro, Functions and more

Max length problem invoked by filevar and fileref

Reply
Contributor
Posts: 29

Max length problem invoked by filevar and fileref

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!

 

 

Super User
Posts: 10,623

Re: Max length problem invoked by filevar and fileref

Posted in reply to xiaoys0725

The file reference in an infile statement with filevar= is just a placeholder.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 29

Re: Max length problem invoked by filevar and fileref

Posted in reply to KurtBremser

Thank you! Can I use any placeholder though? I replaced by something casually but I still have the length limit

Esteemed Advisor
Posts: 5,628

Re: Max length problem invoked by filevar and fileref

Posted in reply to xiaoys0725

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.

PG
Contributor
Posts: 29

Re: Max length problem invoked by filevar and fileref

Ohhhh Ok, thank you!!

Esteemed Advisor
Posts: 5,628

Re: Max length problem invoked by filevar and fileref

Posted in reply to xiaoys0725

When used with filevar, the fileref is just a placeholder, It is ignored.

PG
Super User
Posts: 10,623

Re: Max length problem invoked by filevar and fileref

Posted in reply to xiaoys0725

PS I see no problem in your log.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 29

Re: Max length problem invoked by filevar and fileref

Posted in reply to KurtBremser

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

Ask a Question
Discussion stats
  • 7 replies
  • 136 views
  • 0 likes
  • 3 in conversation