BookmarkSubscribeRSS Feed
piggy
Fluorite | Level 6
Help please.

proc import
out=mailling_working
datafile ="C:\sample\PT&TT.xls";
dbms =excel replace;
sheet = "All Mailed";
mixed =yes;

run;

Since the file PT&TT.xls contains &, SAS would think &TT.xls is macro variable. This problem can be easily solved by changing the file name, but any suggestion to solve this problem without changing the file name? Because I have lots of files contain &.
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
If you read up on SAS Macro processing, you will find out that there are special "Macro Quoting Functions" that protect or hide the normal meaning of special characters, such as % and &. (And do quoting, unquoting, protection at compile time, protection at execution time, etc, etc -- it's a long list.)

Your code -- a single PROC IMPORT step -- without any other macro variable references -- only needs a simple level of protection. The %NRSTR function will do what you want to do -- for the code that you've shown. The correct way to use the %NRSTR function is:
[pre]
datafile ="C:\temp\%nrstr(PT&TT.xls)"
[/pre]

The documentation is here:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#z3514str.htm

In the long run, it might be better to avoid the use of & and % especially in the names of files, because you will continue to have this problem and need to work around it. And eventually, if you -do- need to use & and/or % in their context as macro triggers (such as when you might need to write a macro program), having the & in the file name just complicates things.

cynthia
piggy
Fluorite | Level 6
Thanks for your help.

I am still at beginner level.
This forum is such a good place, it helps me a lot.
ballardw
Super User
A simplier solution IF you do not need to resolve any macro variables elsewhere within the datafile name is to use a single quote ' instead of double quotes ".

Unlike many programming languages SAS supports both types of quotes with the difference involving macro variable resolution.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1536 views
  • 0 likes
  • 3 in conversation