BookmarkSubscribeRSS Feed
Mike_Davis
Fluorite | Level 6


Hello everyone,

I can open Excel console by useing the following SAS code:

options noxwait noxsync;

x '"C:\Program Files\Microsoft Office\Office12\EXCEL"';

My question is:

if I want to use a macro variable express the location of Excel, then it will cause the problem:

options noxwait noxsync ;

%let aaa=C:\Program Files\Microsoft Office\Office12\EXCEL;

x '"&aaa"'; /*This will cause problem*/

Please help!

Thanks!

Mike

4 REPLIES 4
art297
Opal | Level 21

Mike: How about?:

options noxwait noxsync ;

%let aaa=%nrbquote("C:\Program Files\Microsoft Office\Office12\EXCEL");

x &aaa;

Mike_Davis
Fluorite | Level 6

Thank you Art!

That works!

but I have a question,

&aaa can be explained to "C:\Program Files\Microsoft Office\Office12\EXCEL".

you use x &aaa; equal to use x "C:\Program Files\Microsoft Office\Office12\EXCEL".

there missing a couple of '', why still work?

Thanks!

Mike

Ksharp
Super User

Or You can add the path of excel into environment variable PATH , then you can directly use command EXCEL .

x "excel" ;

Tom
Super User Tom
Super User

The actual problem is with Windows (or really DOS) and not SAS.  Your filename has embedded spaces. This can confuse DOS because you might mean that you want it to run the program "C:\Program" with two command line options of "Files\Microsoft" and "Office\Office12\EXCEL".  To clarify for DOS what you mean you need to enclose the filename in quotes.  SAS is stripping the outer quotes before passing the string to DOS.

So add an extra set of quotes.

You can double the interior quotes.

x """&aaa""";

Or use the QUOTE() function to do that for you:

x %sysfunc(quote("&aaa"));

I suspect that why the %BQUOTE() function worked is because it prevented SAS from stripping off the outer quotes before sending the filename to DOS.

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
  • 4 replies
  • 1180 views
  • 6 likes
  • 4 in conversation