I have a variable with a single quote and ampersand that is being invoked when I don't want it to.
In this data step, I am trying to create a variable with a single quote and Ampersand, but I'm getting the error that macro variable W is not resolved. What function can I use to fix this?
Data SC_Mkt;
Retain Supplier Alignment_Geo Alignment_Name Market Region BU;
set SC_ZIP (keep=IMS_ZIP Market Region BU rename=(IMS_ZIP=Alignment_Geo));
Supplier="PAUL";
Alignment_Name="Paul's H&W";
run;
In the following Proc Export, I am trying to use the same name in the outfile name, but also need to be able to invoke the macro for yyyymm and yyyymmdd. How can I fix this?
proc export data=SC_Mkt
outfile="C:\Alignment\&yyyymm Paul's\Upload to RxI\Paul's H&W &yyyymmdd..csv"
DBMS=csv
REPLACE;
run;
quit;
Thank you,
Kelly
outfile="C:\Alignment\&yyyymm Paul%str(%')s\Upload to RxI\Paul%str(%')s %nrstr(H&W) &yyyymmdd..csv"
It is very bad juju to have special characters in directory paths like ',?! and such.
However if you want SAS to resolve to a single quote you can place two single quotes in the text when using a single quote to prevent macro resolution:
Alignment_Name='Paul''s H&W';
But for that path I would strongly suggest not to use any ' or & in the path names. Or at least very carefully evaluate the business logic for having such things.
See Maxim 44. What's said there about blanks goes double for any special characters.
Use a LART on the one who came up with those crazy file- and pathnames.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.