BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_inquisitive
Lapis Lazuli | Level 10

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));
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

1 REPLY 1
Reeza
Super User

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));

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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