SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Onizuka
Pyrite | Level 9

IHello !

 

I am trying to open an Excel file with SAS. There is another topic but i don't find the answer on it (https://communities.sas.com/t5/General-SAS-Programming/opening-an-excel-file-with-SAS/td-p/260934).

 

So there is the code I found on internet :

 

 

%MACRO Sleep(pSeconds);
DATA _NULL_;
vVar1=SLEEP(&pSeconds);
RUN;
%MEND;

%MACRO OpenXls(pFile);
OPTIONS NOXWAIT NOXSYNC MISSING='';
X '"C:\Program Files\Microsoft Office\Office15\EXCEL.EXE / &pFile..xlsx"';
%sleep(2)
%MEND;

I can open Excel if I delete

 / &pfile..xlsx

But if i don't delete this part and i want to open the specific file, it doesn't work :

My file is on a repertory like this :

L:\CLIENTS\XXX\ETUDES\# PROD\111111 vérité\StatTris\2019T1\DATAS\questionnaire long.xlsx

 

Any ideas ?

 

Thank you !

 

Onizuka

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Onizuka
Pyrite | Level 9

I find a solution which is :

  • open Excel first
  • open the file after

 

%macro Open_FileXlsx(nom_fichier); /* nom_fichier is the path + name + extension of the file */
OPTIONS NOXWAIT NOXSYNC MISSING='';
X '"C:\Program Files\Microsoft Office\Office15\EXCEL.EXE "';
%sleep(1);
FILENAME cmds DDE 'Excel|system';
DATA _NULL_;
FILE cmds;
PUT "[open("'"'"&nom_fichier"'"'")]"; 
RUN;
%mend;

View solution in original post

3 REPLIES 3
Onizuka
Pyrite | Level 9

I find a solution which is :

  • open Excel first
  • open the file after

 

%macro Open_FileXlsx(nom_fichier); /* nom_fichier is the path + name + extension of the file */
OPTIONS NOXWAIT NOXSYNC MISSING='';
X '"C:\Program Files\Microsoft Office\Office15\EXCEL.EXE "';
%sleep(1);
FILENAME cmds DDE 'Excel|system';
DATA _NULL_;
FILE cmds;
PUT "[open("'"'"&nom_fichier"'"'")]"; 
RUN;
%mend;
ballardw
Super User

DDE is fragile, not being recommended by Microsoft and the communication approach it uses can be conflicted by other programs such that DDE will not work.

 

So if your approach quits working it is likely to be something external to SAS that changes in your environment.

I found this out when my shop installed Cisco Jabber.

 

You may also have issues with Office 365 as the Microsoft Office no longer has an "Excel.exe", at least not one that I can find.

Onizuka
Pyrite | Level 9

@ballardw wrote:

DDE is fragile, not being recommended by Microsoft and the communication approach it uses can be conflicted by other programs such that DDE will not work.

 

So if your approach quits working it is likely to be something external to SAS that changes in your environment.

I found this out when my shop installed Cisco Jabber.

 

You may also have issues with Office 365 as the Microsoft Office no longer has an "Excel.exe", at least not one that I can find.


Hello, thank you for your answer, I appreciate it 🙂

 

For information, i am in an internship until august. I will provide to the company the code with the DDE but telling that it can have some problems. The problem is that the excel file have differents sheets and we don't have the possibility to import "XLS" or "XLSX" or "EXCEL" files on SAS (unless we convert it in CSV but to long because lot of sheets..)

 

Edit : sorry for my bad english haha

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 4184 views
  • 0 likes
  • 2 in conversation