Hello Frnds,
I have a doubt,
%let srcpath = %nrquote(/PROJECT/sourcefiles/);
%let file1 = %unquote(rohan.txt);
data XXX;
if (fileexist("&scrpath/&file1")) then do;
infile "&srcpath/&file1";
input date1 date9. number;
end;
run;
but this " fileexist("&scrpath/&file1"))" is not working. Code is not able to resole the macro variable. Please help.
Thanks.
You do not need using quote function to mask some special characters for your situation.
%let path=c:\temp\; %let file=class.txt; data x; if fileexist("&path&file") then do; infile "&path&file"; input;list; end; run;
Ksharp
You do not need using quote function to mask some special characters for your situation.
%let path=c:\temp\; %let file=class.txt; data x; if fileexist("&path&file") then do; infile "&path&file"; input;list; end; run;
Ksharp
Ksharp is correct that the quote functions are not needed here, but that does not solve your issue.
The root problem is mis-spelling of macro variable name. You use srcpath in the let statement and scrpath in the fileexist function.
If that does not fix, then please include log for this code.
Thanks Laary.... my bad
Thanks Kshrap. but i still wonder why was "%nrquote" not working
I do not see any trouble with the code (other than the typo in the macro variable name). Do you have a copy of the log with the error message?
Tom and Rohan,
There is another potential problem in addition to the originally identified typo: the path is assigned ending in a "/", but another "/" is added during its use.
All,
In this context on AIX (and HP-UX if my memory is correct), the double-slash, "//" does not cause a problem. Directory navigation will treat as a single-quote. I think this standard behavior across unix flavors, but can not support that. But regardless, my preference would be to leave the terminating '/' out of the macro variable definition.
To reinforce Tom's statement, a log would be nice to have for de-bugging errors.
In general, When we need to handle the macro variable, we need to use quote function to mask these special characters. But For your situation, You only pass the value of macro variable to Data Step Compiler, if you use quote function ,you will get error. Let me give an example.
%let sex=%nrbquote('F');
data female;
set sashelp.class;
where sex=&sex;
run;
This code will produce ERROR. Because you have masked single quote . when it arrived Data Step Compiler,
Compiler only take the value as F ,not 'F'. Why? because you masked this single quote.But If you use the code below, you will get right result. Why? because you didn't mask this single quote ,Compiler can recognize this single quote, Compiler think the value you passed is 'F'.
%let sex='F';
data female;
set sashelp.class;
where sex=&sex;
run;
If you really want to use quote function around the value of macro variable ,then use %unquote to unmask single quote to let Complier know them correctly.
%let sex=%nrbquote('F');
data female;
set sashelp.class;
where sex=%unquote(&sex);
run;
Ksharp
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.