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;
/****************************************************/
/* 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;
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).
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
@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.
@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).
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.
/****************************************************/
/* 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;
How does this answer relate to the original question?
Tom,
When I run the .exe I have an excel output.
thanks,
@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?
Tom,
Yes.
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!
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.