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-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
  • 4 replies
  • 844 views
  • 0 likes
  • 5 in conversation