DATA Step, Macro, Functions and more

argument in filename()

Accepted Solution Solved
Reply
Super Contributor
Posts: 285
Accepted Solution

argument in filename()

Hello,

 

Why the ampersand (&) is not required  for macro variable filrf in this example ?

 

%let filrf=myfile;
%let rc=%sysfunc(filename(filrf, physical-filename));

%if &rc ne 0 %then
	%put %sysfunc(sysmsg());
%let rc=%sysfunc(filename(filrf));

Accepted Solutions
Solution
‎06-18-2018 10:16 PM
Super User
Posts: 23,778

Re: argument in filename()

Posted in reply to SAS_inquisitive

Because filerf is the name you passed to the filename reference to create the reference. If you used the ampersand in both cases it works as well. That's the key - use it both or don't use it both. 

 

%let filrf=myfile; %let rc=%sysfunc(filename(filrf, physical-filename)); <- if this was &filrf you need it in the next step as well. If not, it's the string filrf.

 This should work just as well, and probably what you want. If you check for the existence or to use myfile that will not exist with the above code.

 

%let filrf=myfile;
%let rc=%sysfunc(filename(&filrf, physical-filename));

%if &rc ne 0 %then
	%put %sysfunc(sysmsg());
%let rc=%sysfunc(filename(&filrf));

View solution in original post


All Replies
Solution
‎06-18-2018 10:16 PM
Super User
Posts: 23,778

Re: argument in filename()

Posted in reply to SAS_inquisitive

Because filerf is the name you passed to the filename reference to create the reference. If you used the ampersand in both cases it works as well. That's the key - use it both or don't use it both. 

 

%let filrf=myfile; %let rc=%sysfunc(filename(filrf, physical-filename)); <- if this was &filrf you need it in the next step as well. If not, it's the string filrf.

 This should work just as well, and probably what you want. If you check for the existence or to use myfile that will not exist with the above code.

 

%let filrf=myfile;
%let rc=%sysfunc(filename(&filrf, physical-filename));

%if &rc ne 0 %then
	%put %sysfunc(sysmsg());
%let rc=%sysfunc(filename(&filrf));
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 66 views
  • 1 like
  • 2 in conversation