BookmarkSubscribeRSS Feed
JoaoRFalcao
Calcite | Level 5

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:

JoaoRFalcao_0-1633445960710.png

 

Does anyone know how I can fix this?

 

Reference:

Export zip files using ods 

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

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;

 

JoaoRFalcao
Calcite | Level 5
Thanks! I'll try that!
Kurt_Bremser
Super User

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;
AllanBowe
Barite | Level 11

You could probably achieve it in one line, using this macro:  https://core.sasjs.io/mp__zip_8sas.html

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 765 views
  • 5 likes
  • 4 in conversation