DATA Step, Macro, Functions and more

execute .exe file thru SAS and save the output

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

execute .exe file thru SAS and save the output

 

Dear experst;

 

How to call .exe and get as SAS dataset. when you run the .exe it gives me excel output and I want to save the excel file and process the file using SAS.

 

 data download;

infile 'myfile.exe' pipe;

length A $50;

input A$ B c; * read from output;

putlog _infile_; * show it in the log;

 run;

 

 


Accepted Solutions
Solution
‎11-21-2017 12:43 PM
Contributor
Posts: 70

Re: execute .exe file thru SAS and save the output

/****************************************************/

/* SAVE EXCEL FILES FROM DOWNLOAD */

/***************************************************/

%LET OUT=C:\DOWNLOAD\;

%LET REPORT=BOOK1;

FILENAME COMMANDS DDE 'EXCEL|SYSTEM';

RUN;

%LET FILE = &OUT.&REPORT..XLSX;

RUN;

DATA _NULL_;

FILE COMMANDS;

PUT "[SAVE.AS(""&FILE"")]";

PUT '[QUIT]';

RUN;

View solution in original post


All Replies
Super User
Posts: 10,571

Re: execute .exe file thru SAS and save the output

infile (or filename) pipe expects text in rows, which will end up in your dataset "download" (if the output from myfile.exe is structured correctly).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 70

Re: execute .exe file thru SAS and save the output

Posted in reply to KurtBremser

KurtBremser,

 

It is running with out error, but my biggest concern is how do I save the excel output from .exe. I got this message

 

NOTE: The infile
      'myfile.exe' is:
      Unnamed Pipe Access Device,

      PROCESS=myfile.exe,
      RECFM=V,LRECL=32727


NOTE: 0 records were read from the infile
      'myfile.exe'.
NOTE: The data set WORK.DOWNLOAD has 0 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           44.61 seconds
      cpu time            0.04 seconds

Super User
Posts: 10,571

Re: execute .exe file thru SAS and save the output


tekish wrote:

KurtBremser,

 

It is running with out error, but my biggest concern is how do I save the excel output from .exe. I got this message

 

NOTE: The infile
      'myfile.exe' is:
      Unnamed Pipe Access Device,

      PROCESS=myfile.exe,
      RECFM=V,LRECL=32727


NOTE: 0 records were read from the infile
      'myfile.exe'.
NOTE: The data set WORK.DOWNLOAD has 0 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           44.61 seconds
      cpu time            0.04 seconds


Which means that myfile.exe does not produce any output that SAS can work with.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 13,941

Re: execute .exe file thru SAS and save the output


tekish wrote:

KurtBremser,

 

It is running with out error, but my biggest concern is how do I save the excel output from .exe. I got this message

 


If you run the program without SAS where does the output go? Perhaps you could use the SAS X command or Call System to run the program with parameters to save the output to a known named file, wait for the results (Xsync options), and then read that known output file.

 

I have to say the idea of reading spreadsheet as a data stream feels very likely to be a headache.

 

Something is to check on the actual file format it creates. Some programs lie and are actually creating something that Excel will open but are actually CSV (which SAS can usually handle pretty well) or html (which is poor for data interchange).

Super User
Super User
Posts: 8,279

Re: execute .exe file thru SAS and save the output

The INPUT statement is expecting to read from the standard output generated by the command you are running in the pipe.  For example if I run the TYPE command from a CMD window It will show me the content of a text file on the screen.

 

C:\downloads>type file1.txt
"Hello World"

C:\downloads>

From your SAS log it looks like your program does NOT write anything to the standard output.  Which is good since SAS cannot very easily read a binary file like an EXCEL spreadsheet using the INPUT statement.

 

Open a command window and run that command to see what data if any it write to standard output.

 

Is it possible that your program actually worked, but instead of directing its output to the standard output it just created an actual file somewhere on your disk? If so then you could first run the command and then later read the file that it created in another step.

Solution
‎11-21-2017 12:43 PM
Contributor
Posts: 70

Re: execute .exe file thru SAS and save the output

/****************************************************/

/* SAVE EXCEL FILES FROM DOWNLOAD */

/***************************************************/

%LET OUT=C:\DOWNLOAD\;

%LET REPORT=BOOK1;

FILENAME COMMANDS DDE 'EXCEL|SYSTEM';

RUN;

%LET FILE = &OUT.&REPORT..XLSX;

RUN;

DATA _NULL_;

FILE COMMANDS;

PUT "[SAVE.AS(""&FILE"")]";

PUT '[QUIT]';

RUN;

Super User
Super User
Posts: 8,279

Re: execute .exe file thru SAS and save the output

How does this answer relate to the original question?

Contributor
Posts: 70

Re: execute .exe file thru SAS and save the output

[ Edited ]

Tom,

 

When I run the .exe I have an excel output.

 

thanks,

Super User
Super User
Posts: 8,279

Re: execute .exe file thru SAS and save the output


tekish wrote:

Tom,

 

When I run the .exe I have an excel output.

 

thanks,


Do you mean that after running the program it leaves EXCEL running with the generated content as the currently open workbook?

Contributor
Posts: 70

Re: execute .exe file thru SAS and save the output

Tom,

 

Yes.

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 380 views
  • 0 likes
  • 4 in conversation