Help using Base SAS procedures

Problem of import a 2003 excel file with password into SAS if use macro variable to express password

Reply
Regular Contributor
Posts: 222

Problem of import a 2003 excel file with password into SAS if use macro variable to express password

Hello everyone,

I try to open a password protected excel file as the following SAS code,,,everything works but only problem will happen when I try to use macro variable denotes the password.

Suppose the password of the excel file c:\temp\book1.xls  is abcdefg.

Please look into SAS code ,I add my question there at ""s = '[open(' || quote ("c:\temp\book1.xls.") ||',,,,"abcdefg")]';""   (I want use macro variable express abcdefg will cause problem).

Thanks

Mike

options noxwait noxsync;

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

    data _null_;
        x=sleep(3);
    run;

    filename ExcelCmd dde 'Excel|system';

    data _null_;
      file ExcelCmd;
      length s $200;
      s = '[open(' || quote ("c:\temp\book1.xls.") ||',,,,"abcdefg")]'; /*-------------My question is here,the password is "abcdefg",but I want use a macro variable replace the real password,such as  I want use %let pw=abcdefg,and here I use &pw instead of abcdefg,but a problem will happen-----------------------*/
      put s;
    run;

Frequent Contributor
Posts: 101

Re: Problem of import a 2003 excel file with password into SAS if use macro variable to express password

Posted in reply to Mike_Davis

I'm not familiar with DDE, but have much experience converting code to use macro variables. Try enclosing the DDE command in double quotes instead of single quotes. The single quotes are probably preventing the resolution of the macro &pw, so the proper password does not get passed to Excel.

PROC Star
Posts: 7,492

Re: Problem of import a 2003 excel file with password into SAS if use macro variable to express password

Posted in reply to Mike_Davis

try it with:

      s = '[open(' || quote ("c:\temp\book1.xls.") ||",,,,""&pw."")]";

Regular Contributor
Posts: 222

Re: Problem of import a 2003 excel file with password into SAS if use macro variable to express password

Thank you Art,this works !

Ask a Question
Discussion stats
  • 3 replies
  • 214 views
  • 0 likes
  • 3 in conversation