Calling Macro in String with Apostrope and Ampersand

Reply
New User
Posts: 1

Calling Macro in String with Apostrope and Ampersand

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

Respected Advisor
Posts: 2,155

Re: Calling Macro in String with Apostrope and Ampersand

[ Edited ]
outfile="C:\Alignment\&yyyymm Paul%str(%')s\Upload to RxI\Paul%str(%')s %nrstr(H&W) &yyyymmdd..csv"
--
Paige Miller
Super User
Super User
Posts: 8,634

Re: Calling Macro in String with Apostrope and Ampersand

Importantly, don't use special characters or spaces in filenames and path's, all you are doing is causing problems for yourself. There maybe a coding way round it, however the real problem is putting special characters in filenames/paths.
Super User
Posts: 12,148

Re: Calling Macro in String with Apostrope and Ampersand

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.

 

 

Super User
Posts: 8,589

Re: Calling Macro in String with Apostrope and Ampersand

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 4 replies
  • 90 views
  • 0 likes
  • 5 in conversation