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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Anotherdream
Quartz | Level 8

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

3 REPLIES 3
SASKiwi
PROC Star

Try this:

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Or pop single quotes around it:

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

Anotherdream
Quartz | Level 8

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!


sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 6070 views
  • 0 likes
  • 3 in conversation