Hi everyone!
I am currently trying to make a stored process with two csv files for output. I already know that the best way for doing this is to output a zip file with these two csv files (the stored process only outputs one file).
That being said, I have the code below for doing so:
%let hoje = %sysfunc(today(),date9.);
%let _ODSDETS=TAGSETS.EXCELXP;
%let rc=%sysfunc(stpsrv_header('Content-type','application/vnd.zip')); /*define o tipo de arquivo (zip)*/
%let rc=%sysfunc(stpsrv_header('Content-disposition','attachment; filename=temp.csv'));
%let _ODSSTYLE=PEARL;
ods csv file = 'FILE1_&HOJE..csv' options(autofit_height = 'YES' FROZEN_HEADERS = 'YES');
PROC PRINT DATA=FILE1 noobs LABEL
style(HEADER)={color=black background=white font_weight=bold font_size=10pt font_face=CALIBRI width=1.8in just=c vjust=c}
style(DATA) = {background=white font_size=10pt font_face=CALIBRI};
format MyVAR $char.;
RUN;
ods csv close;
ods csv file = 'FILE2_&HOJE..csv' options(autofit_height = 'YES' FROZEN_HEADERS = 'YES');
PROC PRINT DATA=FILE2 noobs LABEL
style(HEADER)={color=black background=white
font_weight=bold font_size=10pt font_face=CALIBRI width=1.8in just=c vjust=c}
style(DATA) = {background=white font_size=10pt font_face=CALIBRI};
RUN;
ods csv close;
/*criando pasta zipada*/
ods package(newzip) open nopf;
ods package(newzip) add file='FILE1_&HOJE..csv' path=_webout;
ods package(newzip) add file='FILE2_&HOJE..csv';
ods package(newzip) publish archive
properties(
archive_name="Myfiles.zip"
archive_path=_webout
);
ods package(newzip) close;
But the result is an empty file with unknown content type:
Does anyone know how I can fix this?
Reference:
Why so complicated? And why styles for a CSV file?
filename ZIP zip "&wdir/data.zip" member="f1.csv" ;
ods csv file = ZIP;
PROC PRINT DATA=SASHELP.CARS; run;
ods csv close;
filename ZIP zip "&wdir/data.zip" member="f2.csv" ;
ods csv file = ZIP;
PROC PRINT DATA=SASHELP.CARS; run;
ods csv close;
filename ZIP clear;
Instead of ODS CSV & PROC PRINT, use a data step, it performs much better.
file = 'FILE1_&HOJE..csv'
won't work, as the macro variable will not be resolved inside single quotes. You will also have issues because this is not an absolute path, and SAS will try to write the file in the current working directory of the pooled stored process, where you should not have write permission anyway.
As mentioned, you should define a single filename zip to the webout destination, and then use that file reference in the data step with additional members, something along
filename outzip zip _webout;
data _null_;
file outzip(member1.csv) dlm="," dsd;
set ....;
if _n_ = 1 then put "header,information,here";
put .....;
run;
data _null_;
file outzip(member2.csv) dlm="," dsd;
set ....;
if _n_ = 1 then put "header,information,here";
put .....;
run;
You could probably achieve it in one line, using this macro: https://core.sasjs.io/mp__zip_8sas.html
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.