문제

I have a question on how to use the value from a SAS database in another command. In my case, I have a database with two variables (cell and res). "Cell" contains a reference to a cell in an Excel sheet where the value of "res" should be copied.

So I would like to use the value stored in "cell" in my command linking to the Excel sheet. This code does not work (concatenating with || does not work.)

DATA _null_; 
SET test;
FILENAME ExcelTmp DDE "EXCEL|[&myInputTemplate.]&mySheet.!" || cell;
FILE ExcelTmp NOTAB LRECL=7000;
PUT res;
RUN;

Error message:

ERROR 23-2: Invalid option name ||.

1491! DDE "EXCEL|[&myInputTemplate.]&mySheet.!" || cell;
ERROR: Error in the FILENAME statement.
ERROR 23-2: Invalid option name cell.

1492      FILE ExcelTmp NOTAB LRECL=7000;
ERROR 23-2: Invalid option name NOTAB.

If I write

FILENAME ExcelTmp DDE "EXCEL|[&myInputTemplate.]&mySheet.!R1C1:R1C1";

then the value is written to cell A1 in Excel.

Is there some similar approach that works without invoking a macro?

Thanks for your help!

Christoph

도움이 되었습니까?

해결책

The usual way to use values from a dataset as a part of command/statement is CALL EXECUTE routine:

DATA _null_; 
    SET test;
    call execute("DATA _NULL_;");
    call execute(cats("FILENAME ExcelTmp DDE ""EXCEL|[&myInputTemplate.]&mySheet.!",cell,""";"));
    call execute("FILE ExcelTmp NOTAB LRECL=7000;");
    call execute("PUT '"||res||"';");
    call execute("RUN;");
run;

This code generates DATA-steps that stacked up in a buffer and will be executed after the step above is executed. So basically you will generate as many DATA NULL steps as you have records in your test dataset.

다른 팁

Assuming you're trying to update multiple cells, and cell is in the form RnCn, something like this may work...

You also need to determine the cell range beforehand, e.g. R2C2:R100:C5.

%LET RANGE = R2C2:R100C5 ;

DATA _null_; 
SET test;
FILENAME ExcelTmp DDE "EXCEL|[&myInputTemplate.]&mySheet.!&RANGE" ;
FILE ExcelTmp NOTAB LRECL=7000;
put "[select(""" cell """)]" ;
PUT res;
RUN;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top