System environment variables are not usable in ODS FILE= statements


System environment variables can be used in the DATA step FILE statement to write to a file on the system. Please see the following code:


%put %sysget(test);

data _null_;
   file test;
   put "testing";
run;


If the system environment variable TEST exists, points to a valid directory, and includes the name of a file, then that file is created by the DATA step. The ODS destinations must use a FILENAME statement. The following code generates the error message shown below even if the TEST variable resolves to a valid directory and PDF file:

%put %sysget(test);

ods pdf file=test;

proc print data=sashelp.class ; 
run;

ods pdf close;

ERROR: Unable to resolve fileref TEST. ODS PDF initialization fails.
ERROR: Logical name is not available.


All ODS destinations that generate external files, such as HTML, MARKUP, RTF, or PDF, require an explicitly quoted filename or a file reference that has been assigned to an external file for the BODY= or FILE= option. The FILENAME statement must be used to assign a fileref.