filename ftmp "some_file" recfm=n;
The above statement sets a fileref on a file with a specified record format. We've been trying to achieve the same result with a filename function but we keep getting errors.
rcin = filename( ftmp , "some_file" , recfm=n );
The function above doesn't work. We get the following error when using ftmp in the FCOPY function:
ERROR: No logical assign for filename .
How do you specify host options on the filename function? Do we need to use single or double quotes. We can't find any examples online. Because without the recfm it works just fine.
Oh, hang on. I just spotted something. If you run the code it will create a dataset with several variables. Two of those hold return codes from the filename function (rcFB and rcFD). They had the value 20011. I googled for SAS return codes and found documentation that states that error 20011 means "The device type is invalid".
Although device type is an optional argument, apparently you do have to specify it if you want to use host options. So the proper use is:
rcFB = filename( frbron , "&file." , 'DISK' , 'recfm=n' );
rcFD = filename( frdoel , "&file._copy" , 'DISK' , 'recfm=n' );
Thanks to everybody for helping us out.
The host options argument to the function needs to be a character expression. Your
recfm=f
is a numeric expression, namely the Boolean result of the comparison of variable recfm with variable n.
You want
rcin = filename(ftmp,"some_file","recfm=n");
Yes, that was my assumption as well. However, we tried both single and double quotes around the option and it simply doesn't work. This is an example to show how we want to use it:
data testing;
length frbron frdoel $8;
rcFB = filename( frbron , "&file." , 'recfm=n' );
rcFD = filename( frdoel , "&file._copy" , 'recfm=n' );
rcCP = fcopy( frbron , frdoel );
if rcCP not = 0 then do;
errmsg = sysmsg();
put "FCOPY fout --> " rcFB= rcFD= rcCP= errmsg=;
put "bron = " BronFile;
put "doel = " DoelFile;
end;
run;
Without that third argument in the filename function, FCOPY does work but corrupts the file. With the third argument added (between quotes) we get the following error:
ERROR: No logical assign for filename .
But the option works perfectly on the filename statement. So we can use that as a work around, but we're very curious how you're supposed to do it with a filename function.
Oh, hang on. I just spotted something. If you run the code it will create a dataset with several variables. Two of those hold return codes from the filename function (rcFB and rcFD). They had the value 20011. I googled for SAS return codes and found documentation that states that error 20011 means "The device type is invalid".
Although device type is an optional argument, apparently you do have to specify it if you want to use host options. So the proper use is:
rcFB = filename( frbron , "&file." , 'DISK' , 'recfm=n' );
rcFD = filename( frdoel , "&file._copy" , 'DISK' , 'recfm=n' );
Thanks to everybody for helping us out.
You don't have to specify the device type, it will use the default when not specified, but you do need to leave space for it in argument list.
rcFB = filename( frbron , "&file." , , 'recfm=n' );
Also note that if you use a variable name, such as FRBRON in your code, as the fileref then how it defines the actual fileref is complicated. When the variable is populated then the value is used as the fileref, just as if you had passed a constant string. But when the variable is empty then the FILENAME() function will choose a fileref and STORE the value into the variable. Plus if you call it with only the filref argument then in addition to closing the fileref it will also set the variable to blanks.
I would swear that we tried using a blank third argument yesterday, but apparently we didn't. And I get what you're saying about using a variable for the fileref. I'm not sure how that got into our code. I assume it is because it was in another example. Indeed the following works as well:
rcFB = filename( "fn_A" , "&file." , , 'recfm=n' );
rcFD = filename( "fn_B" , "&file._copy" , , 'recfm=n' );
rcCP = fcopy( "fn_A" , "fn_B" );
Best to read the documentation as it spells out what types of values each argument can contain.
filename ftmp "some_file" recfm=n;
data _null_;
rc=filename('ftmp', "some_file",'recfm=n');
run;
Yes, we did read the documentation, but nowhere does it show an example how to properly specify host options. We had already tried your suggestion (between quotations marks) and that doesn't work.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.