3

I have SAS stored process that ceates DBF file from SAS data set rr_udf_value and finds its size (F_SIZE):

filename dbfout "/SASInside/DBF/myfile";

proc export
   data=rr_udf_value
   outfile=dbfout
   dbms=dbf
   replace;
run; 

%let f_nm=/SASInside/DBF/myfile.DBF;

%let rc=%sysfunc(filename(onefile, &f_nm.));
%let fid=%sysfunc(fopen(&onefile));
%let F_SIZE=%sysfunc(finfo(&fid,File Size (bytes)));
%put &F_SIZE;

The problem is that the variable F_SIZE is empty in STP log. But if after execution of STP I run commands

%let f_nm=/SASInside/DBF/myfile.DBF;

%let rc=%sysfunc(filename(onefile, &f_nm.));
%let fid=%sysfunc(fopen(&onefile));
%let F_SIZE=%sysfunc(finfo(&fid,File Size (bytes)));
%put FSIZE=&F_SIZE;

manually, everithing is OK: F_SIZE=17342.

Why F_SIZE is not initialized while running STP, and how could I fix it?

Thanks in advance!

Joe
  • 62,789
  • 6
  • 49
  • 67
PierreVanStulov
  • 425
  • 2
  • 11
  • Any warnings or errors? Is F_SIZE uninitialized, or blank (these are different)? When you say manually, is that running on the same server as the STP is with 100% definitely the same permissions (in particular, I wonder if `fopen` requires XCMD)? – Joe Jun 11 '15 at 16:44
  • No warnings or erors, but variable fid=0 (it means that fopen fails while running in STP). F_SIZE is blank. I run the program on the same server. STP succesfully creates DBF file, so I think has reuired permissions to check its size. Am I right? – PierreVanStulov Jun 11 '15 at 17:00
  • Well, I'm not entirely talking disk permissions. Some processes that use shell-like access (ie, `x`, `syscmd`, etc.) are forbidden on server environments by default. This apparently includes `filename` (see [this article](http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#win-sysop-xcmd.htm) for example.) So I would either add a check for what the value of `xcmd` option is on your STP server, or talk to your server admin. – Joe Jun 11 '15 at 17:03
  • Hey, Joe! Yes ou are right! The problem was in permissions. I switched STP option "Server type" to "Workspace server only" and STP reurned file size. So, thank ou very much! – PierreVanStulov Jun 11 '15 at 17:10
  • Glad to hear - I've put that as an answer. (Specifically, the XCMD issue- which may be your difference here.) If it's actually related to something slightly different, you should put your own answer with more specifics (as I don't know actually what "Workspace Server Only" does). – Joe Jun 11 '15 at 17:13

1 Answers1

2

filename() is restricted in environments with OPTION NOXCMD, which is by default set for server environments. This is for security reasons (as XCMD allows shell access). You can enable this with by enabling OPTION XCMD, though your server admin (if this is not you) would have to enable it on the server and not in your local session typically.

See the SAS documentation on XCMD for more information.

Joe
  • 62,789
  • 6
  • 49
  • 67
  • I also found that filesize can be obtained with simpler instrucions: `filename x '/SASInside/DBF/myfile'; proc sql; select * from dictionary.EXTFILES where Fileref='X'; quit;` and without switching server type. – PierreVanStulov Jun 16 '15 at 09:51
  • @PierreVanStulov Please post that as an answer - and if it solved your problem, accept it! – Joe Jun 16 '15 at 14:13