BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rohan
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

View solution in original post

8 REPLIES 8
Ksharp
Super User

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

LarryWorley
Fluorite | Level 6

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.Smiley Happy

If that does not fix, then please include log for this code.

Rohan
Calcite | Level 5

Thanks Laary.... my bad Smiley Sad

Rohan
Calcite | Level 5

Thanks Kshrap. but i still wonder why was "%nrquote" not working

Tom
Super User Tom
Super User

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?

art297
Opal | Level 21

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.

LarryWorley
Fluorite | Level 6

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. 

Ksharp
Super User

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 3555 views
  • 1 like
  • 5 in conversation