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.
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!
Try this:
%let csvfile=%nrstr(P&I ARREARAGE_brandonsfile.csv);
Or pop single quotes around it:
%let csvfile='P&I ARREARAGE_brandonsfile.csv';
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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.