By specifying a cell range you are telling SAS to overwrite any existing data in that range with data from your SAS dataset.
Try the XLSX LIBNAME engine and the PROC DATASETS APPEND statement to get closer to what you want.
The range= option may not avaliable when exporting Microsoft Excel files using the XLS and XLSX Identifiers: https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acpcref/n0msy4hy1so0ren1acm90iijxn8j.htm#p...
I recommend you the DDE method, it may be old, but very useful:
proc export data=sashelp.class outfile='C:\Profiles\test.xlsx' dbms=xlsx replace;
newfile=yes;
sheet='Sheet1';
run;
options noxwait noxsync;
x '"C:\Profiles\test.xlsx"';
%let rc=%sysfunc(sleep(5)); *Wait for opening Excel;
filename xlsx dde "excel|Sheet1!r23c2:r100c6";
data _null_;
file xlsx;
set sashelp.class;
put name sex age height weight;
run;
The result:
@Hao_Luo wrote:
The range= option may not avaliable when exporting Microsoft Excel files using the XLS and XLSX Identifiers: https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acpcref/n0msy4hy1so0ren1acm90iijxn8j.htm#p...
I recommend you the DDE method, it may be old, but very useful:
However the communications channels that DDE uses may be preempted by other programs.
I had one process that used DDE, been a few years, but when our IT department added Cisco Jabber to our suite of standard applications the process no longer worked while Jabber was active. In this case I was able to KILL the Jabber process using Windows Task Manager, closing the application window was not sufficient, and it would run. But determining which programs may be interfering could be a nightmare.
Hello everyone
Thank you for your help. I will try to understand what you have suggested.
I don't have much experience with SAS, so I don't understand everything I see here.
I am being told by sas that proc export does not allow
writing to a range yet you say you are doing it. I have
included your post to them for resolution. Any citations of
people writing to excel ranges would be appreciated.
One suspects that you asked a different question than just "export to range", such as the original poster of this thread that was OVERWRITING values already in the spreadsheet and not the desired behavior.
For example the online help for SAS 9.4.4 includes this portion:
A Range of Data in an Excel Worksheet
The SAS C Files Server that works with SAS/ACCESS treats an Excel workbook as a database, and a range (subset of cells in a worksheet) as a table. A range name must be defined in the Excel file before SAS can use it. A worksheet is treated as a special range. A worksheet name appended with a $ character is treated as a range.
Also there is a big difference between XLS, XLSX files and which versions of the Office suite are installed (or not) and what is possible with the Office files.
@ASimpleCaveman - The RANGE option is supported for both the EXCEL and EXCELCS DBMS options of PROC EXPORT but not for XLS and XLSX DBMSs. If your SAS servers run on Unix then the EXCEL option wont be available, but EXCELCS is if you have the SAS PC Files Server installed.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.