Question

I have a piece of code in SAS that outputs to Excel using DDE and which works fine. I'm now trying to make it a little more dynamic, but I can't figure out how to write the path line (2. line) to the Excel file.

options noxwait noxsync;

x '"c:\Folder\excelfile_&date_yyyymmdd\Holding\Holding.xls'";
/* Putting SAS in sleep mode to give Excel the necessary time to open the file */
data _null_; x=sleep(5);
run;
FILENAME TEST DDE "EXCEL|SV01-01!r8c2:r20000c29" notab;
    DATA _NULL_;
   SET le_hk3;

It works fine when I replace the macro variable with it's value and it also seems to be resolving correctly but it still doesn't open the file. The log says the file doesn't exist. I've tried using double quotes, double and triple dots "..xls" in various combinations, but it still doesn't work.

Was it helpful?

Solution

SAS does not replace macro variables inside single quotes. Also, you need to indicate the end or the name of the macro variable with a dot. For instance, I can't tell if your macro variable is &date_yyyymmdd or &date. Assuming the first:

x """c:\Folder\excelfile_&date_yyyymmdd.\Holding\Holding.xls""";

I prefer to build the full name as a separate macro variable so that I can test it:

/* double quotes are included if specified a macro variable */
%let quoted_file = "c:\Folder\excelfile_&date_yyyymmdd.\Holding\Holding.xls";

data _null_;
put &quoted_file;
x &quoted_file;

run;

pT

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top