0

DDEを介してExcelファイルで検索と置換を行うSASプログラムを作成しようとしています。具体的には、ヘッダー行で文字列間のスペース (" ") を検索し、スペースなし ("") に置き換えようとしています。

たとえば、「Test Name」を含むセルがある場合、検索と置換を行って「TestName」にします。

これは私が持っているものです:

options noxwait noxsync;

/* Open Excel */
x '"C:\Program Files (x86)\Microsoft Office\Office14\excel.exe"';
filename cmds dde 'excel|system';
data _null_;
    x=sleep(5);
run;

/* Open File and Manipulate*/
data _null_; 
    file cmds; 
    put '[open("C:\filename.xls")]'; 
    put '[select("R1")]';
    put '[formula.replace(" ","",1,,false,false)]'; 
run;

/*Close File*/
data _null_;
    file cmds;
    put '[FILE-CLOSE("C:\filename.xls")]';
    put '[QUIT()]';
run;

検索と置換機能が機能していません。そのステートメントを読み取った後、ログに次のように表示されます。

NOTE: The file CMDS is:
    DDE Session,
    SESSION=excel|system,RECFM=V,LRECL=256

ERROR: DDE session not ready.
FATAL: Unrecoverable I/O error detected in the execution of the DATA step program.  
    Aborted during the EXECUTION phase.
NOTE: 2 records were written to the file CMDS.
    The minimum record length was 21.
    The maximum record length was 70.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
    real time           0.63 seconds
    cpu time            0.00 seconds

助言がありますか?

また、 Formula.replace ステートメントのパラメータが何であるかを知っている人はいますか? 最初と2番目があなたが見つけたいものであり、それを置き換えたいものであることを私は知っています. ドキュメントを見つけるのに苦労しています。

4

2 に答える 2

1

http://www.lexjansen.com/wuss/2007/ApplicationsDevelopment/APP_SmithC_ImportingExcelFiles.pdf

パスまたはファイル名を間違って入力すると、Excel はブックを開けません。SAS ログに次のようなエラー メッセージが表示されます。

NOTE: The file DDECMD is:
      DDE Session,
      SESSION=excel|system,RECFM=V,LRECL=256
ERROR: DDE session not ready.
FATAL: Unrecoverable I/O error detected in the execution of the data step program.
       Aborted during the EXECUTION phase.
NOTE: 0 records were written to the file DDECMD.
NOTE: The SAS System stopped processing this step because of errors.
于 2014-10-28T07:49:38.857 に答える
0

私の提案は、これを行うための Excel (VBA) マクロを作成してから、そのマクロを呼び出すことです。これにより、コードを記述したり、コンテキストの手がかりを取得したりするためのはるかに優れた IDE が得られるだけでなく、より多くの制御が可能になります。別のワークブックからマクロを呼び出すことができるので、これが繰り返し実行する必要がある場合でも (そうなると思います)、自動化されたファイルとは別に開く「マクロ」テンプレート ワークブックにこれを配置できます。

于 2013-05-09T17:44:57.717 に答える