<?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: How to get number of rows in zipped CSV before importing in 9.2 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392493#M94462</link>
    <description>&lt;P&gt;The SASZIPAM engine is not something that's fully documented/supported for customer use. &amp;nbsp;The FILENAME ZIP method is pretty good, supports ZIP files (and GZIP very soon now - in SAS 9.4 Maint 5) and member-level access. &amp;nbsp;But behind the scenes, the file will need to be extracted from the ZIP in order for SAS to know anything about it, including record count -- and that's going to require whatever amount of space is needed to store the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FILENAME ZIP is available only in SAS 9.4 and later though -- not in SAS 9.2. &amp;nbsp;You can play with it in the SAS University Edition to learn more, though that won't help in your production environment.&lt;/P&gt;</description>
    <pubDate>Fri, 01 Sep 2017 11:50:58 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2017-09-01T11:50:58Z</dc:date>
    <item>
      <title>How to get number of rows in zipped CSV before importing in 9.2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392473#M94448</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I managed to import zipped CSV files using the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FILENAME ZIPFILE SASZIPAM "Z:\Data\fname001.zip";
data work.imported. (COMPRESS = YES);
infile ZIPFILE(fname001.csv)
       delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2;
informat a b c ;
format a b c;
input a b c;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, sometimes when I am importing large CSV files (~4.5m rows, &amp;gt;8GB in without zipping), I encountered I/O error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After trial and error, I noticed that I can successfully import using the above code by reducing the observation read in by 1 row, using the OBS= option after FIRSTOBS=2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This brought me two questions:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Why was there an I/O error only when the last row included?&lt;/LI&gt;
&lt;LI&gt;How can I know the total number of rows in the CSV file so that I can skip the last row when building an import macro?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 11:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392473#M94448</guid>
      <dc:creator>J_CKY</dc:creator>
      <dc:date>2017-09-01T11:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get number of rows in zipped CSV before importing in 9.2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392478#M94451</link>
      <description>&lt;P&gt;Have you tried this method from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;of extracting the zipped file first&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/Importing-the-data-from-zipped-csv-file/td-p/284292" target="_blank"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/Importing-the-data-from-zipped-csv-file/td-p/284292&lt;/A&gt; and then running Proc Import?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 11:07:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392478#M94451</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-09-01T11:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get number of rows in zipped CSV before importing in 9.2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392479#M94452</link>
      <description>Won't work.  v9.2 do not have FILENAME ZIP method.</description>
      <pubDate>Fri, 01 Sep 2017 11:08:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392479#M94452</guid>
      <dc:creator>J_CKY</dc:creator>
      <dc:date>2017-09-01T11:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to get number of rows in zipped CSV before importing in 9.2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392482#M94454</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/36192"&gt;@J_CKY&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;You can't know the number of rows (=the number of line delimiters) of a text file before you've fully scanned it. The number of rows is not a metadata attribute of such a file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before the introduction of the ZIP engine I've always used 3rd party tools (preferrably 7-zip; calling it via a SAS pipe) when dealing with zip files in SAS. The SASZIPAM engine has some limitations and I've always managed to avoid dealing with it.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 11:15:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392482#M94454</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-01T11:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to get number of rows in zipped CSV before importing in 9.2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392483#M94455</link>
      <description>&lt;P&gt;Ok your post says this happens sometimes - could it be that you're running out of space - I suspect that reading zip files must involve the creation of some utility files behind the scenes and if you try with a fresh SAS session it might work?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 11:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392483#M94455</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-09-01T11:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to get number of rows in zipped CSV before importing in 9.2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392484#M94456</link>
      <description>Thanks for your input.  &lt;BR /&gt;Unfortunately, I do not have access to 7-zip at work and red-tapes here prevents me from getting it. &lt;BR /&gt;&lt;BR /&gt;I would have used 7zip method if I have the choice. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
      <pubDate>Fri, 01 Sep 2017 11:21:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392484#M94456</guid>
      <dc:creator>J_CKY</dc:creator>
      <dc:date>2017-09-01T11:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to get number of rows in zipped CSV before importing in 9.2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392487#M94457</link>
      <description>&lt;P&gt;yes, sometimes only.&amp;nbsp; And also those larger CSV files&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that was caused by some dodgy footer or something of that sort.&amp;nbsp; If I can get the number of row in advance, I can program it to avoid the last row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But seems like this is not possible without an attempt to import it (and fail) and then find out in the log.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 11:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392487#M94457</guid>
      <dc:creator>J_CKY</dc:creator>
      <dc:date>2017-09-01T11:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to get number of rows in zipped CSV before importing in 9.2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392490#M94459</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/36192"&gt;@J_CKY&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I would assume if you can run something like below to get the count of lines then the file is structurally o.k.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile .... end=last;
  input;
  count+1;
  if last then
    call symput('count',count);
run;
%put &amp;amp;=count;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If above fails then yes, something more serious is not right.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 11:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392490#M94459</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-01T11:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to get number of rows in zipped CSV before importing in 9.2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392493#M94462</link>
      <description>&lt;P&gt;The SASZIPAM engine is not something that's fully documented/supported for customer use. &amp;nbsp;The FILENAME ZIP method is pretty good, supports ZIP files (and GZIP very soon now - in SAS 9.4 Maint 5) and member-level access. &amp;nbsp;But behind the scenes, the file will need to be extracted from the ZIP in order for SAS to know anything about it, including record count -- and that's going to require whatever amount of space is needed to store the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FILENAME ZIP is available only in SAS 9.4 and later though -- not in SAS 9.2. &amp;nbsp;You can play with it in the SAS University Edition to learn more, though that won't help in your production environment.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 11:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392493#M94462</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-09-01T11:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to get number of rows in zipped CSV before importing in 9.2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392501#M94466</link>
      <description>&lt;P&gt;So &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;'s way works with a smaller file (17k rows) but getting an I/O error when working with a 4.5m row file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: Invalid compressed data, length does not match.
FATAL: Unrecoverable I/O error detected in the execution of the DATA step program.
       Aborted during the EXECUTION phase.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hmmm... I guess that's something to do with the buffer?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 12:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392501#M94466</guid>
      <dc:creator>J_CKY</dc:creator>
      <dc:date>2017-09-01T12:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to get number of rows in zipped CSV before importing in 9.2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392707#M94531</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/36192"&gt;@J_CKY&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I could replicate the error in my environment (local SAS9.4 Win7 instance) using below code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename testzip zip 'c:\test\testfile.zip';
data _null_;
  file testzip(testfile.txt);
  array vars {5} $100 (5*'  adslkfasdlfkas;dfkjd daflk;jadsfkdjdk jdlkaj;dfadk;;ldsaf |');
  do i=1 to 45*10**6;
    put i '|' vars[*];
  end;
run;
filename testzip clear;


filename zipfile saszipam "c:\test\testfile.zip";
data _null_;
  infile zipfile(testfile.txt) end=last;
  input;
  count+1;
  if last then
    call symput('count',put(count,best32.));
run;
filename zipfile clear;
%put &amp;amp;=count;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;NOTE: The infile ZIPFILE(testfile.txt) is:
      File Name=testfile.txt,
      Compressed Size=148520385,
      Uncompressed Size=4294967295,
      Compression Level=-1,Clear Text=Yes

ERROR: Invalid compressed data, length does not match.
FATAL: Unrecoverable I/O error detected in the execution of the DATA step program.  Aborted during the EXECUTION phase.
NOTE: A total of 45000000 records were read from the infile library ZIPFILE.
NOTE: 45000000 records were read from the infile ZIPFILE(testfile.txt).
      One or more lines were truncated.
NOTE: The SAS System stopped processing this step because of errors.&lt;/PRE&gt;
&lt;P&gt;As you I'm only running into this issue once the zipped file exceeds a certain size.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had no problems reading the same file using the SAS9.4 ZIP engine with code as below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename testzip zip 'c:\test\testfile.zip';
data _null_;
  infile testzip(testfile.txt) end=last;
  input;
  count+1;
  if last then
    call symput('count',put(count,best32.));
run;
filename testzip clear;
%put &amp;amp;=count;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Given that the SASZIPAM engine is not meant for public use I guess you will either have to use a 3rd party tool like 7-zip or you need to upgrade to a more recent version of SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;7-zip comes also in a portable version (also the command line bit) so I guess you could&amp;nbsp;make this work in your environment even if you don't have the permissions to install software.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Sep 2017 03:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392707#M94531</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-02T03:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to get number of rows in zipped CSV before importing in 9.2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392752#M94549</link>
      <description>&lt;P&gt;Sounds like you have hit the limit of the ability of that filename egine and your work around is just going to ignore the end of the file.&lt;/P&gt;
&lt;P&gt;You either need to update your SAS version (why are you still using a program that is over 7 years old when newer versions are available for no extra money?) or switch to using ZIP ro 7z or other utility that can handle those files.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Sep 2017 14:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-number-of-rows-in-zipped-CSV-before-importing-in-9-2/m-p/392752#M94549</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-02T14:41:47Z</dc:date>
    </item>
  </channel>
</rss>

