<?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 Loading large CSV to sas dataset a “chunk” at a time in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Loading-large-CSV-to-sas-dataset-a-chunk-at-a-time/m-p/903747#M83123</link>
    <description>I have a large csv file. I only want to load a 10,000 rows at a time. I don’t know how exactly how large it is, but it is over 4 million rows. I played around with proc import but I can’t get that to work for a range of rows.</description>
    <pubDate>Sat, 18 Nov 2023 01:35:06 GMT</pubDate>
    <dc:creator>jody4001</dc:creator>
    <dc:date>2023-11-18T01:35:06Z</dc:date>
    <item>
      <title>Loading large CSV to sas dataset a “chunk” at a time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Loading-large-CSV-to-sas-dataset-a-chunk-at-a-time/m-p/903747#M83123</link>
      <description>I have a large csv file. I only want to load a 10,000 rows at a time. I don’t know how exactly how large it is, but it is over 4 million rows. I played around with proc import but I can’t get that to work for a range of rows.</description>
      <pubDate>Sat, 18 Nov 2023 01:35:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Loading-large-CSV-to-sas-dataset-a-chunk-at-a-time/m-p/903747#M83123</guid>
      <dc:creator>jody4001</dc:creator>
      <dc:date>2023-11-18T01:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Loading large CSV to sas dataset a “chunk” at a time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Loading-large-CSV-to-sas-dataset-a-chunk-at-a-time/m-p/903752#M83124</link>
      <description>&lt;P&gt;You don't need to use PROC IMPORT to read a CSV file.&amp;nbsp; Those are just simple TEXT files.&amp;nbsp; You can just write your own data step to read them.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do know what is in the file right?&amp;nbsp; or is someone expecting you to GUESS what it contains?&amp;nbsp; Seems like strange request for a file with that many rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are forced to guess how to read it you might want to use this macro instead.&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/csv2ds.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/csv2ds.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition to working for some files that PROC IMPORT cannot handle it will also let you use a random sample of the data rows to use to make the guessing of how to read it faster.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It also writes cleaner data step code to read the file.&amp;nbsp; And you can ask it to save the generated code to a file for you.&amp;nbsp; Which will make it easier for you to use that code as your starting point for reading only a few of the rows, if you really still need to do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To read only some of the observations from a text file use the FIRSTOBS= and OBS= options on the INFILE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data part1;
  infile 'myfile.csv' dsd truncover firstobs=2 obs=10001;
  ....
run;

data part2;
  infile 'myfile.csv' dsd truncover firstobs=10002 obs=20001;
  ....
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Nov 2023 04:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Loading-large-CSV-to-sas-dataset-a-chunk-at-a-time/m-p/903752#M83124</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-18T04:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: Loading large CSV to sas dataset a “chunk” at a time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Loading-large-CSV-to-sas-dataset-a-chunk-at-a-time/m-p/906105#M83178</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;In case you want to use only SAS then then the approach by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; is what one needs to follow.&lt;BR /&gt;However in case you have access to bash shell, the large file can be split into a number of smaller&amp;nbsp; files having 10,000 lines each.&lt;BR /&gt;The command would be as follows. Please do test it.&lt;/P&gt;
&lt;PRE&gt; split -l 10000 --numeric-suffixes input_filename output_prefix&lt;/PRE&gt;
&lt;P&gt;You will get out put&amp;nbsp; files with the name output_prefix01, output_prefix02.....&lt;BR /&gt;The next step would be to write a code to read these files one file at a time.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 20:07:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Loading-large-CSV-to-sas-dataset-a-chunk-at-a-time/m-p/906105#M83178</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2023-12-04T20:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: Loading large CSV to sas dataset a “chunk” at a time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Loading-large-CSV-to-sas-dataset-a-chunk-at-a-time/m-p/906124#M83179</link>
      <description>Why?&lt;BR /&gt;&lt;BR /&gt;Proc import is slow, so if you read it in using a data step it's quite easy. 4 million isn't much for SAS to process at all.</description>
      <pubDate>Mon, 04 Dec 2023 21:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Loading-large-CSV-to-sas-dataset-a-chunk-at-a-time/m-p/906124#M83179</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-12-04T21:03:43Z</dc:date>
    </item>
  </channel>
</rss>

