<?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: Getting the checksum of a ZIP file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-checksum-of-a-ZIP-file/m-p/653272#M196227</link>
    <description>&lt;P&gt;You can extract the possible information items by running a loop from 1 to &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n0obx7o9ceaq31n1xwpddcub8d7f.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;FOPTNUM()&lt;/A&gt; and use the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n1ocdzkn9uhsa7n1qv3wwp4d3dot.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;FOPTNAME()&lt;/A&gt; function, but I don't know of any checksums provided by operating systems.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jun 2020 15:45:15 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-06-04T15:45:15Z</dc:date>
    <item>
      <title>Getting the checksum of a ZIP file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-checksum-of-a-ZIP-file/m-p/653227#M196212</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;Hello everyone,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;I am new to this forum and pretty much to SAS in general, so if there are any beginner mistakes from my side, I apologise in advance!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;My task ist to get the File size and the md5 checksum of some ZIP files I created with SAS. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;To get the file size I used &amp;nbsp;the fopen and finfo functions, which worked very well.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;In this&lt;/FONT&gt; &lt;A href="https://blogs.sas.com/content/sasdummy/2017/09/08/filename-zip-details/" target="_self"&gt;SAS Blog&lt;/A&gt;&amp;nbsp;I read, that you can acess the checksum of a zip file with finfo(fid, 'CR-32').&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;Sadly it does not work on my files. I get ‚202020202020202020202020‘ as a result, so i assume it is just a blank in the hex32 format. I have to say, I dind´t find this option in the official SAS documentation.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Why does this option not work on my Code? Is it because it does not work in general, or because the checksum information is not saved in the ZIP file?&lt;/FONT&gt; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;If getting the checksum with finfo is not possible, is there another simple alternative to get the checksum from an extern ZIP file with SAS? I created the ZIP files with the ODS Option in SAS, maybe it is simpler to get the checksum during the creation of the ZIP File? Any suggestions about that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data XXXX;

* Assign the fileref '_FILES' to the directory location;
FILENAME _FILES "XXXPATH";

FORMAT              md5                                      $hex32.


* Opens up the directory, dir is now the directory id;
dirid=dopen('_FILES');

* Numfiles is equivalent to the number of files in the directory;
numfiles=dnum(dirid);

* Loop around each file;
do i=1 to numfiles;
                * Identify the file as fname;
                Filename=dread(dirid,i);
                * Find the file in the location;
                file=" XXXPATH "||Filename;
                * Assign the fileref '_FNAMES' to this file;
                sysrc=filename('_FNAMES', file);
                * Open the file;
                fid          =fopen('_FNAMES');

                * If the files is open;
                if fid ^= 0 then do;
                               * Get all of the file information;
                               Bytes     =finfo(fid            ,'File Size (Bytes)');
                               md5       =finfo(fid            ,'md5');
                               * Output for each file in the directory;
                               output;
                               * Close the file;
                               sysrc=fclose(fid);
                end;
end;

* Close the directory;
rc=close(dirid);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 13:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-checksum-of-a-ZIP-file/m-p/653227#M196212</guid>
      <dc:creator>LeinadBCN</dc:creator>
      <dc:date>2020-06-04T13:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the checksum of a ZIP file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-checksum-of-a-ZIP-file/m-p/653272#M196227</link>
      <description>&lt;P&gt;You can extract the possible information items by running a loop from 1 to &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n0obx7o9ceaq31n1xwpddcub8d7f.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;FOPTNUM()&lt;/A&gt; and use the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n1ocdzkn9uhsa7n1qv3wwp4d3dot.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;FOPTNAME()&lt;/A&gt; function, but I don't know of any checksums provided by operating systems.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 15:45:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-checksum-of-a-ZIP-file/m-p/653272#M196227</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-04T15:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the checksum of a ZIP file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-checksum-of-a-ZIP-file/m-p/660070#M197619</link>
      <description>&lt;P&gt;Thank you for your answer. If I untersand it correctly. what you propose is the same as what I did with fopen() and finfo() just with another function.&lt;/P&gt;&lt;P&gt;Do you know any simple way to get the checksum of a zip file, that was created in SAS itself? Maybe a Code during the zipping process itself?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2020 15:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-checksum-of-a-ZIP-file/m-p/660070#M197619</guid>
      <dc:creator>LeinadBCN</dc:creator>
      <dc:date>2020-06-16T15:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the checksum of a ZIP file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-checksum-of-a-ZIP-file/m-p/660092#M197622</link>
      <description>&lt;P&gt;Checksums (for the purpose of verification) are created with utilities like md5 and not stored in the files themselves.&lt;/P&gt;
&lt;P&gt;The ZIP file format contains checksums of the uncompressed data for each individual file within the archive, according to&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Zip_(file_format)" target="_blank" rel="noopener"&gt;https://en.wikipedia.org/wiki/Zip_(file_format)&lt;/A&gt;. I see no reference to a "whole file" checksum there, either.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if you want to have a checksum for a zip file, you best use a checksumming utility like md5.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2020 15:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-checksum-of-a-ZIP-file/m-p/660092#M197622</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-16T15:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the checksum of a ZIP file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-checksum-of-a-ZIP-file/m-p/660099#M197623</link>
      <description>&lt;P&gt;You probably will need to use some external program to extract that information.&lt;/P&gt;
&lt;P&gt;For example if you have unzip command available you can use the -v option to get output like:&lt;/P&gt;
&lt;PRE&gt;Archive:  test1.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
    2954  Defl:N      415  86% 01-10-2017 23:15 2d31d6fc  dir1/test1.xml
   68096  Defl:N     9441  86% 02-19-2009 13:28 d368efe9  ../cepsusr.doc
   68096  Defl:N     9441  86% 02-19-2009 13:28 d368efe9  cepsusr.doc
--------          -------  ---                            -------
  139146            19297  86%                            3 files&lt;/PRE&gt;
&lt;P&gt;So you can then just use the PIPE engine to run it and read the output into a dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data files ;
  infile 'unzip -v test1.zip' pipe firstobs=4 truncover ;
  input @;
  if _infile_=:'------' then stop;
  input length method :$20. size cmpr :percent. date :mmddyy. time :time. crc_32 :$8. name $256. ;
  format date yymmdd10. time time5. ;
run;
proc print width=min;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    length    method    size    cmpr       date       time      crc_32          name

 1       2954    Defl:N     415    0.86    2017-01-10    23:15    2d31d6fc    dir1/test1.xml
 2      68096    Defl:N    9441    0.86    2009-02-19    13:28    d368efe9    ../cepsusr.doc
 3      68096    Defl:N    9441    0.86    2009-02-19    13:28    d368efe9    cepsusr.doc&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jun 2020 16:13:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-checksum-of-a-ZIP-file/m-p/660099#M197623</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-16T16:13:29Z</dc:date>
    </item>
  </channel>
</rss>

