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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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