I have this code:
proc export data=finaldata
outfile="&ExportLoc./finaldata_%sysfunc(today(),yymmddN.)%sysfunc(hour(%sysfunc(time())),z2.)%sysfunc(minute(%sysfunc(time())),z2.)%sysfunc(second(%sysfunc(time())),z2.)_123.txt"
dbms=dlm replace;
delimiter='|';
run;
I want to take what is created from there to export out into a zipped file. I have the below code but the log says it can't find the physical file because it doesn't exist. What am I missing?
ods package(newzip) open nopf;
ods package(newzip) add file="&ExportLoc./finaldata_%sysfunc(today(),yymmddN.)%sysfunc(hour(%sysfunc(time())),z2.)%sysfunc(minute(%sysfunc(time())),z2.)%sysfunc(second(%sysfunc(time())),z2.)_123.txt";
ods package(newzip) publish archive
properties(
archive_name="finaldata_%sysfunc(today(),yymmddN.)%sysfunc(hour(%sysfunc(time())),z2.)%sysfunc(minute(%sysfunc(time())),z2.)%sysfunc(second(%sysfunc(time())),z2.)_123.zip"
archive_path="&ExportLoc."
);
ods package(newzip) close;
Hi,
How about by using filename ZIP? By the way I suggest you to use proc format to have "easier" file naming:
/* Assuming we have this: */
%let ExportLoc = %sysfunc(pathname(work));
data finaldata;
set sashelp.class;
run;
/* to make naming textfie easier! */
proc format;
picture myDatetime (default=14)
other='%Y%0m%0d%0H%0M%0S' (datatype=datetime)
;
run;
/* reference to ZIP device */
filename f ZIP "&ExportLoc./newzip.zip" member = "finaldata_%sysfunc(datetime(), myDatetime.)_123.txt";
proc export data=finaldata
outfile=f
dbms=dlm
replace;
delimiter='|';
run;
Bart
Post the full log will help. But since you're using time and date, my guess is that the time doesn't match exactly anymore. If you run it a minute later your file will have a different name so you cannot use dynamic time references when you need to do something list. I would suggest creating the filename once and then using it through the process.
%let file_export = &ExportLoc./finaldata_%sysfunc(today(),yymmddN.)%sysfunc(hour(%sysfunc(time())),z2.)%sysfunc(minute(%sysfunc(time())),z2.)%sysfunc(second(%sysfunc(time())),z2.)_123;
proc export data=finaldata
outfile= "&file_export..txt"
dbms=dlm replace;
delimiter='|';
run;
ods package(newzip) open nopf;
ods package(newzip) add file="&file_export..txt";
ods package(newzip) publish archive
properties(
archive_name="&file_export..zip"
archive_path="&ExportLoc."
);
ods package(newzip) close;
@InspectahDex wrote:
I have this code:
proc export data=finaldata
outfile="&ExportLoc./finaldata_%sysfunc(today(),yymmddN.)%sysfunc(hour(%sysfunc(time())),z2.)%sysfunc(minute(%sysfunc(time())),z2.)%sysfunc(second(%sysfunc(time())),z2.)_123.txt"
dbms=dlm replace;
delimiter='|';
run;
I want to take what is created from there to export out into a zipped file. I have the below code but the log says it can't find the physical file because it doesn't exist. What am I missing?
ods package(newzip) open nopf;
ods package(newzip) add file="&ExportLoc./finaldata_%sysfunc(today(),yymmddN.)%sysfunc(hour(%sysfunc(time())),z2.)%sysfunc(minute(%sysfunc(time())),z2.)%sysfunc(second(%sysfunc(time())),z2.)_123.txt";
ods package(newzip) publish archive
properties(
archive_name="finaldata_%sysfunc(today(),yymmddN.)%sysfunc(hour(%sysfunc(time())),z2.)%sysfunc(minute(%sysfunc(time())),z2.)%sysfunc(second(%sysfunc(time())),z2.)_123.zip"
archive_path="&ExportLoc."
);
ods package(newzip) close;
Because the code will be part of an automated process, I need to do this all in one step without having to run the entire program twice.
Hi,
How about by using filename ZIP? By the way I suggest you to use proc format to have "easier" file naming:
/* Assuming we have this: */
%let ExportLoc = %sysfunc(pathname(work));
data finaldata;
set sashelp.class;
run;
/* to make naming textfie easier! */
proc format;
picture myDatetime (default=14)
other='%Y%0m%0d%0H%0M%0S' (datatype=datetime)
;
run;
/* reference to ZIP device */
filename f ZIP "&ExportLoc./newzip.zip" member = "finaldata_%sysfunc(datetime(), myDatetime.)_123.txt";
proc export data=finaldata
outfile=f
dbms=dlm
replace;
delimiter='|';
run;
Bart
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.