BookmarkSubscribeRSS Feed
brophykl
Calcite | Level 5

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

4 REPLIES 4
PaigeMiller
Diamond | Level 26
outfile="C:\Alignment\&yyyymm Paul%str(%')s\Upload to RxI\Paul%str(%')s %nrstr(H&W) &yyyymmdd..csv"
--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26
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.
ballardw
Super User

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.

 

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1339 views
  • 0 likes
  • 5 in conversation