Ampersand in file name, causing problems

Accepted Solution Solved
Reply
Super Contributor
Posts: 418
Accepted Solution

Ampersand in file name, causing problems

I am trying to read in a file with an ampersand in it's name. Please see the code below for an example of what i'm trying to do (simplified the fields obviously).

data Notworking

infile "C:\Test this\Csv Files\&csvfile."   dlm=','  lrecl=10 dsd;

length varnumcsv 3. name $1.;

input name $;

;

varnumCSV=_n_;

run;

The problem is the macro variable &Csvfile.  is a macro that is defined as the name of a csv file within a directory, during this loop it resolves too.

%let csvfile=P&I ARREARAGE_brandonsfile.csv;

2028      %put &csvfile.;

WARNING: Macro variable "&I" was not resolved

WARNING: Macro variable "&I" was not resolved

P&I ARREARAGE_brandonsfile.csv

I would like to mask the & from WITHIN the macro variable, so that it doesnt' try to resolve the macro &I at run time (instead treats it JUST as a string). I am not sure how to do this. I know this is probably a simple solution so sorry for its simplicity.


Accepted Solutions
Solution
‎06-06-2014 05:48 PM
Super Contributor
Posts: 418

Re: Ampersand in file name, causing problems

I was actually able to solve this using the "%superq(Macrovariablename)"  trick.

I can't really put single quotes around the variable because the string is deffined WITHIN a macro variable, and therefore it is trying to resolve before the single quotes are defined.  Thanks for the tips tho!


View solution in original post


All Replies
Super User
Posts: 3,112

Re: Ampersand in file name, causing problems

Try this:

%let csvfile=%nrstr(P&I ARREARAGE_brandonsfile.csv);

Super User
Super User
Posts: 7,407

Re: Ampersand in file name, causing problems

Or pop single quotes around it:

%let csvfile='P&I ARREARAGE_brandonsfile.csv';

Solution
‎06-06-2014 05:48 PM
Super Contributor
Posts: 418

Re: Ampersand in file name, causing problems

I was actually able to solve this using the "%superq(Macrovariablename)"  trick.

I can't really put single quotes around the variable because the string is deffined WITHIN a macro variable, and therefore it is trying to resolve before the single quotes are defined.  Thanks for the tips tho!


☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 799 views
  • 0 likes
  • 3 in conversation