<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Zipping binary files in SAS OnDemand in SAS Software for Learning Community</title>
    <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856772#M940</link>
    <description>&lt;P&gt;Thank you for this, Reeza, I'll read that document and try out the solution!&lt;/P&gt;</description>
    <pubDate>Wed, 01 Feb 2023 23:51:26 GMT</pubDate>
    <dc:creator>tonybesas</dc:creator>
    <dc:date>2023-02-01T23:51:26Z</dc:date>
    <item>
      <title>Zipping binary files in SAS OnDemand</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856676#M932</link>
      <description>&lt;P&gt;I'm using SAS OnDemand and would like to zip up lots of png files (graphs) generated through SAS PROC SGPLOT.&lt;BR /&gt;&lt;BR /&gt;I tried the suggestion below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Software-for-Learning/Bulk-Download-all-my-files-from-SAS-Ondemand/m-p/712727#M613" target="_self"&gt;https://communities.sas.com/t5/SAS-Software-for-Learning/Bulk-Download-all-my-files-from-SAS-Ondemand/m-p/712727#M613&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This worked well with text files (.html, .sas, .tsv, etc.), but not with the png files (charts, for instance). With the png files, the zip is generated, downloads and opens fine, but the png files in it are damaged.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas appreciated, thank you ahead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data filelist;
length dname filename $256 dir level 8 lastmod size 8;
format lastmod datetime20.;
input dname;
retain filename ' ' level 0 dir 1;
cards4;
/home/path...
;;;;
data filelist;
modify filelist;
rc1=filename('tmp',catx('/',dname,filename));
rc2=dopen('tmp');
dir = not not rc2;
if not dir then do;
fid=fopen('tmp','i',0,'b');
lastmod=input(finfo(fid,foptname(fid,5)),NLDATM100.);
size=input(finfo(fid,foptname(fid,6)),32.);
fid=fclose(fid);
end;
else do;
dname=catx('/',dname,filename);
filename=' ';
lastmod=input(dinfo(rc2,doptname(rc2,5)),NLDATM100.);
end;
replace;
if dir;
level=level+1;
do i=1 to dnum(rc2);
filename=dread(rc2,i);
output;
end;
rc3=dclose(rc2);
run;
filename out zip "/home/path.../png.zip ";
%macro write_single(fname);
data _null_;
infile "&amp;amp;fname";
file out("&amp;amp;fname");
input;
put _infile_;
run;
%mend;
data _null_;
set filelist;
where filename ne "" and scan(filename,-1,".") = "png";
call execute('%write_single('!!catx("/",dname,filename)!!")");
run;
&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Feb 2023 15:57:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856676#M932</guid>
      <dc:creator>tonybesas</dc:creator>
      <dc:date>2023-02-01T15:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Zipping binary files in SAS OnDemand</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856684#M933</link>
      <description>&lt;P&gt;Did you try telling SAS to treat the files as BINARY by modifying these two lines in the macro?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile "&amp;amp;fname";
file out("&amp;amp;fname");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Feb 2023 16:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856684#M933</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-01T16:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Zipping binary files in SAS OnDemand</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856743#M934</link>
      <description>&lt;P&gt;Thank you for your reply . I just tried:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
infile "&amp;amp;fname" recfm=N  ;
file out("&amp;amp;fname") recfm=N ;
input;
put _infile_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but got the following error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="sasLogError5_1675286565321" class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: The '_INFILE_' INPUT/PUT statement option is inconsistent with binary mode I/O.  The execution of the DATA STEP is being terminated.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 01 Feb 2023 21:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856743#M934</guid>
      <dc:creator>tonybesas</dc:creator>
      <dc:date>2023-02-01T21:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Zipping binary files in SAS OnDemand</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856752#M935</link>
      <description>&lt;P&gt;Either used fixed length:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile "&amp;amp;fname" recfm=F lrecl=256  ;
file out("&amp;amp;fname") recfm=F lrecl=256;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps try using FCOPY() function instead.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 21:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856752#M935</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-01T21:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Zipping binary files in SAS OnDemand</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856755#M936</link>
      <description>How are you generating the output? Worth wrapping it all in ODS PACKAGE to have it zipped for you? Just tested that and it works fine for the images with ODS PACKAGE.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings09/018-2009.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings09/018-2009.pdf&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 01 Feb 2023 21:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856755#M936</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-02-01T21:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Zipping binary files in SAS OnDemand</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856759#M937</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* list all files in your directory */

data filelist;
run;
data filelist;
  length root dname $ 2048 filename $ 256 dir level 8;
  input root;
  retain filename dname ' ' level 0 dir 1;
cards4;
&amp;lt;/your/directory/with files&amp;gt;
;;;;
run;

data filelist;
  modify filelist;
  rc1=filename('tmp',catx('/',root,dname,filename));
  rc2=dopen('tmp');
  dir = 1 &amp;amp; rc2;
  if dir then 
    do;
      dname=catx('/',dname,filename);
      filename=' ';
    end;
  replace;

  if dir;

  level=level+1;

  do i=1 to dnum(rc2);
    filename=dread(rc2,i);
    output;
  end;
  rc3=dclose(rc2);
run;

proc sort data=filelist;
  by root dname filename;
run;

/* print out files list too see if you have all you want */
proc print data=filelist;
run;



/* name the zip file you want to zip into, e.g. */
%let addcntzip = /home/myuser/myZIPfile.zip;

data _null_;

  set filelist; /* loop over all files */
  if dir=0;

  rc1=filename("in" , catx('/',root,dname,filename), "disk", "lrecl=1 recfm=n");
  rc1txt=sysmsg();
  rc2=filename("out", "&amp;amp;addcntzip.", "ZIP", "lrecl=1 recfm=n member='" !! catx('/',dname,filename) !! "'");
  rc2txt=sysmsg();

  do _N_ = 1 to 6; /* push into the zip...*/
    rc3=fcopy("in","out");
    rc3txt=sysmsg();
    if fexist("out") then leave; /* if success leave the loop */
    else sleeprc=sleep(0.5,1); /* if fail wait half a second and retry (up to 6 times) */
  end;

  rc4=fexist("out");
  rc4txt=sysmsg();

/* just to see errors */
  put _N_ @12 (rc:) (=);

run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 22:33:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856759#M937</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-02-01T22:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: Zipping binary files in SAS OnDemand</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856769#M938</link>
      <description>&lt;P&gt;Thank you! This worked very well! Here's the code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data filelist;
  length dname filename $256 dir level 8 lastmod size 8;
  format lastmod datetime20.;
  input dname;
  retain filename ' ' level 0 dir 1;
cards4;
/home/&amp;lt;your username in SAS OnDemand&amp;gt;/&amp;lt;your folder&amp;gt;
;;;;

data filelist;
  modify filelist;
  rc1=filename('tmp',catx('/',dname,filename));
  rc2=dopen('tmp');
  dir = not not rc2;
  if not dir then do;
    fid=fopen('tmp','i',0,'b');
    lastmod=input(finfo(fid,foptname(fid,5)),NLDATM100.);
    size=input(finfo(fid,foptname(fid,6)),32.);
    fid=fclose(fid);
  end;
  else do;
    dname=catx('/',dname,filename);
    filename=' ';
    lastmod=input(dinfo(rc2,doptname(rc2,5)),NLDATM100.);
  end;
  replace;
  if dir;
  level=level+1;
  do i=1 to dnum(rc2);
    filename=dread(rc2,i);
    output;
  end;
  rc3=dclose(rc2);
run;

filename out zip "/home/&amp;lt;your username in SAS OnDemand&amp;gt;/&amp;lt;your folder&amp;gt;/png.zip";

%macro write_single(fname);

data _null_;
infile "&amp;amp;fname" recfm=F lrecl=256  ;  /* this is specific to BINARY files */
file out("&amp;amp;fname") recfm=F lrecl=256; /* this is specific to BINARY files */
input;
put _infile_;
run;

%mend;

data _null_;
set filelist;
where filename ne "" and scan(filename,-1,".") = "png";
call execute('%write_single('!!catx("/",dname,filename)!!")");
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Feb 2023 23:45:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856769#M938</guid>
      <dc:creator>tonybesas</dc:creator>
      <dc:date>2023-02-01T23:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: Zipping binary files in SAS OnDemand</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856771#M939</link>
      <description>&lt;P&gt;This worked great, thank so much! It zipped up everything in my folder, including the text files and the binary files as well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 23:50:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856771#M939</guid>
      <dc:creator>tonybesas</dc:creator>
      <dc:date>2023-02-01T23:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Zipping binary files in SAS OnDemand</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856772#M940</link>
      <description>&lt;P&gt;Thank you for this, Reeza, I'll read that document and try out the solution!&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 23:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856772#M940</guid>
      <dc:creator>tonybesas</dc:creator>
      <dc:date>2023-02-01T23:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: Zipping binary files in SAS OnDemand</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856773#M941</link>
      <description>I kind of like that option as it's simple to add in to a report process so that you get a zip file for the full report. Makes it easy if you're automating a report that runs monthly for example.</description>
      <pubDate>Thu, 02 Feb 2023 00:05:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Zipping-binary-files-in-SAS-OnDemand/m-p/856773#M941</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-02-02T00:05:31Z</dc:date>
    </item>
  </channel>
</rss>

