<?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 import a large .csv file into SAS if it includes the 'extra' comma? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447883#M112592</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194466"&gt;@France&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;besides, could you explain the meaning of these codes for&amp;nbsp;me&amp;nbsp;please ? where could I write data name, path of infile and variables?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* 'Fix' a CSV file that is missing qutoes around a specific variable *;
%let outfile=fixed;
%let infile=sample;
%let nvars=26 ;
%let fixcol=8;
data _null_;
  infile &amp;amp;infile dsd truncover ;
  file &amp;amp;outfile dsd ;
  length x1-x&amp;amp;nvars next $200. ;
  input x1-x&amp;amp;fixcol. @;
  do i=1 to countw(_infile_,',','m')-&amp;amp;nvars ;
    input next @;
    x&amp;amp;fixcol=cats(x&amp;amp;fixcol,',',next); 
  end;
  input x%eval(&amp;amp;fixcol+1)-x&amp;amp;nvars;
  put x1-x&amp;amp;nvars;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;thanks in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The easiest way to understand code is to take on the roll of the compiler and the data step and see what the statements do.&amp;nbsp; Since this is using macro variables make sure to first resolve the macro variables and macro functions and then evaluate the resulting code.&amp;nbsp; The %LET's are just setting values.&amp;nbsp; Basically you should be able to reuse the code and only change the values assigned to the macro variables in the %LET statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first two macro variables define the input and output files. In this example I am using filerefs that were previously defined by FILENAME statments. You could also just use physical filenames but you would then need to include the quotes around the names so that when expanded they make sense in the INFILE and FILE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The next macro variable defines how many fields SHOULD be in each line. For your file it is 26.&lt;/P&gt;
&lt;P&gt;The next macro variable defined which field will "get' all of the extra commas.&amp;nbsp; For your two example lines it was number 8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I said before the data step just reads the line into separate character variables and the writes it back out.&amp;nbsp; Let's look at some of the details.&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;infile dsd truncover ;
  file &amp;amp;outfile dsd ;
  length x1-x&amp;amp;nvars next $200. ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;We are going to use a DATA _NULL_ step since we are not creating any SAS dataset, just another text file.&amp;nbsp; The INFILE and FILE statement define what we want to read.&amp;nbsp; If you have really long lines (greater than 32K) then you can add LRECL= options to both of these.&amp;nbsp; The LENGTH statement defines the variables we are going to use. One for each field and one extra one we will use to read the extra values.&amp;nbsp; I have set them all to max of 200 characters. If any of the fields in your data are longer than that then change the number.&amp;nbsp; Notice that we use the macro variable NVARS to set the upper bound on the variable list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  input x1-x&amp;amp;fixcol. @;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22493"&gt;@so&lt;/a&gt; first we read up to the column where the extra commas might appear. The&amp;nbsp;@ on the INPUT statement holds the line so we can use another INPUT statement to read more later.&amp;nbsp; Again notice the use of the macro variable FIXCOL to define the upper bound on the variable list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  do i=1 to countw(_infile_,',','m')-&amp;amp;nvars ;
    input next @;
    x&amp;amp;fixcol=cats(x&amp;amp;fixcol,',',next); 
  end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is part that is dealing with the extra commas.&amp;nbsp; If the number of fields in the line (as counted by the COUNTW() function) is less than or equal to number expected then this loop never runs.&amp;nbsp; Otherwise it runs once for each extra comma.&amp;nbsp; So if there are 2 extra commas it will run twice.&amp;nbsp; Each time it reads the next word into NEXT and appends it along with a comma to the value of the target field.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  input x%eval(&amp;amp;fixcol+1)-x&amp;amp;nvars;
  put x1-x&amp;amp;nvars;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now all that is left to do is read the rest of the columns and write the values back out to the new file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 22 Mar 2018 18:42:42 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-03-22T18:42:42Z</dc:date>
    <item>
      <title>how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447507#M112436</link>
      <description>&lt;P&gt;when I am importing a large .csv file into SAS by using following codes,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data SASDATA.Applications ;&lt;BR /&gt;infile 'R:/Li/PATSTAT/Applications.csv' DLM = ',' DSD missover lrecl=32767 firstobs = 3 ;&lt;BR /&gt;input&lt;BR /&gt;&amp;nbsp; appln_id :29.&lt;BR /&gt;&amp;nbsp; appln_auth :$29.&lt;BR /&gt;&amp;nbsp; appln_nr :$29.&lt;BR /&gt;&amp;nbsp; appln_kind :$29.&lt;BR /&gt;&amp;nbsp; appln_filing_date :YYMMDD10.&lt;BR /&gt;&amp;nbsp; appln_filing_year&lt;BR /&gt;&amp;nbsp; appln_nr_epodoc :$50.&lt;BR /&gt;&amp;nbsp; appln_nr_original :$150.&lt;BR /&gt;&amp;nbsp; ipr_type :$29.&lt;BR /&gt;&amp;nbsp; internat_appln_id :29.&lt;BR /&gt;&amp;nbsp; int_phase :$29.&lt;BR /&gt;&amp;nbsp; reg_phase :$29.&lt;BR /&gt;&amp;nbsp; nat_phase :$29.&lt;BR /&gt;&amp;nbsp; earliest_filing_date :YYMMDD10.&lt;BR /&gt;&amp;nbsp; earliest_filing_year&lt;BR /&gt;&amp;nbsp; earliest_filing_id :29.&lt;BR /&gt;&amp;nbsp; earliest_publn_date :YYMMDD10.&lt;BR /&gt;&amp;nbsp; earliest_publn_year&lt;BR /&gt;&amp;nbsp; earliest_pat_publn_id :29.&lt;BR /&gt;&amp;nbsp; granted :29.&lt;BR /&gt;&amp;nbsp; docdb_family_id :29.&lt;BR /&gt;&amp;nbsp; inpadoc_family_id :29.&lt;BR /&gt;&amp;nbsp; docdb_family_size :29.&lt;BR /&gt;&amp;nbsp; nb_citing_docdb_fam :29.&lt;BR /&gt;&amp;nbsp; nb_applicants :29.&lt;BR /&gt;&amp;nbsp; nb_inventors :29.&lt;BR /&gt;;&lt;BR /&gt;format&lt;BR /&gt;&amp;nbsp; appln_filing_date :YYMMDDd10.&lt;BR /&gt;&amp;nbsp; appln_filing_year :YEAR10.&lt;BR /&gt;&amp;nbsp; earliest_filing_date :YYMMDDd10.&lt;BR /&gt;&amp;nbsp; earliest_filing_year :YEAR10.&lt;BR /&gt;&amp;nbsp; earliest_publn_date :YYMMDDd10.&lt;BR /&gt;&amp;nbsp; earliest_publn_year :YEAR10.&lt;BR /&gt;;&lt;BR /&gt;run ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the log shows&amp;nbsp;information like&amp;nbsp;following:&lt;/P&gt;&lt;P&gt;NOTE: Invalid data for internat_appln_id in line 3457514 61-62.&lt;/P&gt;&lt;DIV class="sasNote"&gt;NOTE: Invalid data for earliest_filing_date in line 3457514 70-70.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Invalid data for earliest_filing_year in line 3457514 72-81.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Invalid data for earliest_publn_date in line 3457514 88-95.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Invalid data for earliest_publn_year in line 3457514 97-106.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;3457514 3574782,BR,7600215,A ,1976-04-08,1976,BR19767600215,&lt;U&gt;&lt;STRONG&gt;760215,&lt;/STRONG&gt;&lt;/U&gt;,PI,0,N,N,Y,1975-04-14,1975,411&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;91 49045,1976-10-05,1976,312739797,0,19727905,327504,29,56,1,2 149&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;appln_id=3574782 appln_auth=BR appln_nr=7600215 appln_kind=A appln_filing_date=1976-04-08&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;appln_filing_year=1965 appln_nr_epodoc=BR19767600215 appln_nr_original=760215 ipr_type=&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;internat_appln_id=. int_phase=0 reg_phase=N nat_phase=N earliest_filing_date=.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;earliest_filing_year=. earliest_filing_id=1975 earliest_publn_date=. earliest_publn_year=.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;earliest_pat_publn_id=1976 granted=312739797 docdb_family_id=0 inpadoc_family_id=19727905&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;docdb_family_size=327504 nb_citing_docdb_fam=29 nb_applicants=56 nb_inventors=1 _ERROR_=1&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;_N_=3457513&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;or like this&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;NOTE: Invalid data for internat_appln_id in line 3780547 57-58.&lt;DIV class="sasNote"&gt;NOTE: Invalid data for earliest_filing_date in line 3780547 66-66.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Invalid data for earliest_filing_year in line 3780547 68-77.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Invalid data for earliest_publn_date in line 3780547 84-91.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Invalid data for earliest_publn_year in line 3780547 93-102.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;3780547 3897835,CA,182,A ,1967-09-15,1967,CA19670000182,&lt;U&gt;&lt;STRONG&gt;000,182&lt;/STRONG&gt;&lt;/U&gt;,PI,0,N,N,Y,1966-09-16,1966,2248546&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;91 0,1975-03-18,1975,315362359,1,10420177,1874780,14,0,1,1 145&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;appln_id=3897835 appln_auth=CA appln_nr=182 appln_kind=A appln_filing_date=1967-09-15&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;appln_filing_year=1965 appln_nr_epodoc=CA19670000182 appln_nr_original=000 ipr_type=182&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;internat_appln_id=. int_phase=0 reg_phase=N nat_phase=N earliest_filing_date=.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;earliest_filing_year=. earliest_filing_id=1966 earliest_publn_date=. earliest_publn_year=.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;earliest_pat_publn_id=1975 granted=315362359 docdb_family_id=1 inpadoc_family_id=10420177&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;docdb_family_size=1874780 nb_citing_docdb_fam=14 nb_applicants=0 nb_inventors=1 _ERROR_=1&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;U&gt;as I confirm 'PI' should be recorded in the 'ipr_type' volume, the&amp;nbsp;problem should be caused by 'extra' comma . besides the data set is too large to correct one by one.&lt;/U&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;U&gt;what should I do for it?&lt;/U&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;thanks in advance.&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 21 Mar 2018 17:32:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447507#M112436</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-03-21T17:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447508#M112437</link>
      <description>&lt;P&gt;Doesn't PATSTAT also provide JSON files? Maybe that may be easier to parse out and won't have this issue. I'm surprised it does.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you upload some records in a CSV file that we can work with.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 17:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447508#M112437</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-21T17:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447510#M112438</link>
      <description>And does it occur in all records or only some? if only some make sure to include that variability in the sample data.</description>
      <pubDate>Wed, 21 Mar 2018 17:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447510#M112438</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-21T17:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447555#M112461</link>
      <description>&lt;P&gt;Didn't you ask this question (in different words) already?&lt;/P&gt;
&lt;P&gt;Did you try adapting the solution from the other question to this data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really need to talk to the creators of the CSV file and ask that takes steps to insure they are creating valid CSV files. That is that any value that contains the delimiter is quoted.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or at least use some method that creates files that CAN be interpreted.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 19:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447555#M112461</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-21T19:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447575#M112471</link>
      <description>&lt;P&gt;Doesn't PATSTAT provide the SQL queries? With some small modifications those will run in SAS...&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447575#M112471</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-21T20:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447582#M112474</link>
      <description>&lt;P&gt;PATSTAT Online provide SQL queries. but I am using 2016 autumn edition while the PATSTAT online only provides 2017 spring edition and 2017 autumn edition. is that ok?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447582#M112474</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-03-21T20:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447587#M112478</link>
      <description>&lt;P&gt;i think it is occurred in some records.This attribute is not created by PATSTAT but collect form different patent&amp;nbsp;authorities. that might be the reason why these mistakes happened.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:49:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447587#M112478</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-03-21T20:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447589#M112480</link>
      <description>&lt;P&gt;Hi. As an alternative you could&amp;nbsp; start by reading all fields as character strings and then find a way to clean that up.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447589#M112480</guid>
      <dc:creator>JohnHoughton</dc:creator>
      <dc:date>2018-03-21T20:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447593#M112482</link>
      <description>&lt;P&gt;I think there is no JOSN files. Besides, could you tell me how to split a csv file please? the all file is too big to upload.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447593#M112482</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-03-21T20:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447598#M112485</link>
      <description>&lt;P&gt;But the patstat manual says it can save as xml&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 21:06:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447598#M112485</guid>
      <dc:creator>JohnHoughton</dc:creator>
      <dc:date>2018-03-21T21:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447611#M112492</link>
      <description>&lt;P&gt;If you have powershell&amp;nbsp; (Windows will automatically) you can use this approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;gc -path file_name.csv - head N &amp;gt; output.txt&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Mar 2018 22:19:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447611#M112492</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-21T22:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447612#M112493</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194466"&gt;@France&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;i think it is occurred in some records.This attribute is not created by PATSTAT but collect form different patent&amp;nbsp;authorities. that might be the reason why these mistakes happened.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is this one of their free files? If so, post the link then.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 22:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447612#M112493</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-21T22:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447630#M112502</link>
      <description>&lt;P&gt;You don't show any value with imbedded commas. If there are none you might test a line to see if the number of expected is commas is too large or too small suppose that your data should have 27 variables with exactly 26 commas separating the values and NO commas inside any of the text field:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input @;&lt;/P&gt;
&lt;P&gt;if countc(_infile_,',') ne 26 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; put "WARNING: Unexpected number of variables on line " _n_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; input;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else input&lt;/P&gt;
&lt;P&gt;&amp;lt;your variable list&amp;gt;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But this won't work if any of the text fields can have a comma in side a column. And really only cleans up the log as you would have to examine that data file closely to fix the text in whatever manner is needed.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 23:19:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447630#M112502</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-21T23:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447674#M112507</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194466"&gt;@France&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;i think it is occurred in some records.This attribute is not created by PATSTAT but collect form different patent&amp;nbsp;authorities. that might be the reason why these mistakes happened.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is this one of their free files? If so, post the link then.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you PAID for this file then insist that they fix it.&amp;nbsp; They can either use a delimiter that does not appear in any field. Or add quotes around values that contain the delimiter. They could even use the goofy syntax that some database support of adding a backslash in front off delimiters that appear in the data.&amp;nbsp; At minimum they need to provide a file that can be parsed by a rule, which this file cannot.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 03:51:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447674#M112507</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-22T03:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447677#M112509</link>
      <description>&lt;P&gt;Try a little divide an conquer.&lt;/P&gt;
&lt;P&gt;Read the records with the right number of commas and dump the other one into a new file.&lt;/P&gt;
&lt;P&gt;Then figure out how to read them or fix them and then read them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename badrows 'R:/Li/PATSTAT/Applications_bad.csv' ;

data SASDATA.Applications ;
infile 'R:/Li/PATSTAT/Applications.csv' DLM = ',' DSD missover lrecl=32767 firstobs = 3 ;
input @ ;
if countw(_infile_,',','m') ne 26 then do ;
  file badrows ;
  put _infile_;
  delete;
end;

input ....&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Mar 2018 04:19:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447677#M112509</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-22T04:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447678#M112510</link>
      <description>&lt;P&gt;Here is an example program that could be used to "fix" a CSV file where only one column could have extra commas.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* 'Fix' a CSV file that is missing qutoes around a specific variable *;
%let outfile=fixed;
%let infile=sample;
%let nvars=26 ;
%let fixcol=8;
data _null_;
  infile &amp;amp;infile dsd truncover ;
  file &amp;amp;outfile dsd ;
  length x1-x&amp;amp;nvars next $200. ;
  input x1-x&amp;amp;fixcol. @;
  do i=1 to countw(_infile_,',','m')-&amp;amp;nvars ;
    input next @;
    x&amp;amp;fixcol=cats(x&amp;amp;fixcol,',',next); 
  end;
  input x%eval(&amp;amp;fixcol+1)-x&amp;amp;nvars;
  put x1-x&amp;amp;nvars;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Basically you tell it what file to read and where to write the fixed file. You tell it how many columns there should be and which column to assume all of the extra commas should be placed into.&lt;/P&gt;
&lt;P&gt;It then reads the line into variables with a loop to read any extra values into that specific column and writes it back out.&lt;/P&gt;
&lt;P&gt;Let's try it on your two example rows. Let's make a sample data file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename sample temp;
data _null_;
  file sample;
  put
 '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26'
/'3574782,BR,7600215,A ,1976-04-08,1976,BR19767600215,760215,,PI,0,N,N,Y,1975-04-14,1975,41149045,1976-10-05,1976,312739797,0,19727905,327504,29,56,1,2'
/'3897835,CA,182,A ,1967-09-15,1967,CA19670000182,000,182,PI,0,N,N,Y,1966-09-16,1966,22485460,1975-03-18,1975,315362359,1,10420177,1874780,14,0,1,1'
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then run the program above.&lt;/P&gt;
&lt;P&gt;And then look at the result.&lt;/P&gt;
&lt;PRE&gt;323   data _null_;
324     infile &amp;amp;outfile ;
325     input ;
326     list;
327   run;

NOTE: The infile FIXED is:
      Filename=xxx\#LN00054,
      RECFM=V,LRECL=32767,File Size (bytes)=370,
      Last Modified=22Mar2018:00:41:48,
      Create Time=22Mar2018:00:41:48

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
1         1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26 68
2         3574782,BR,7600215,A,1976-04-08,1976,BR19767600215,"760215,",PI,0,N,N,Y,1975-04-14,1975,41149045,197
     101  6-10-05,1976,312739797,0,19727905,327504,29,56,1,2 150
3         3897835,CA,182,A,1967-09-15,1967,CA19670000182,"000,182",PI,0,N,N,Y,1966-09-16,1966,22485460,1975-03
     101  -18,1975,315362359,1,10420177,1874780,14,0,1,1 146
NOTE: 3 records were read from the infile FIXED.
      The minimum record length was 68.
      The maximum record length was 150.
&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Mar 2018 04:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447678#M112510</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-22T04:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447709#M112525</link>
      <description>&lt;P&gt;1.Could you explain what is the meaning of this code please?&lt;/P&gt;&lt;P&gt;for example, should I use the following code if I want to extract volume from 3457514 to 3780578 ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;gc &lt;SPAN class="token operator"&gt;- R:/Li/PATSTAT/Applications.csv&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt; head &lt;SPAN&gt;3457514 to 3780578&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;gt;&lt;/SPAN&gt; output&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;txt&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2.&amp;nbsp;&lt;A href="https://data.epo.org/access-control/welcome?lg=en" target="_blank"&gt;https://data.epo.org/access-control/welcome?lg=en&lt;/A&gt; this is the link to PATSTAT database. you can click the 'PATSTAT Online' on that page, and then you can register&amp;nbsp;for a free trial of PATSTAT Online.&amp;nbsp;Please note that&amp;nbsp;&lt;SPAN&gt;PATSTAT Online free trials are valid for one month. &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 10:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447709#M112525</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-03-22T10:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447710#M112526</link>
      <description>thanks for your advice. I am not sure about it as it is given by my supervisor. but I will try to ask them to fix the data set.</description>
      <pubDate>Thu, 22 Mar 2018 10:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447710#M112526</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-03-22T10:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447722#M112530</link>
      <description>&lt;P&gt;many thanks for your help. I am running&amp;nbsp;the dataset by your codes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 10:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447722#M112530</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-03-22T10:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a large .csv file into SAS if it includes the 'extra' comma?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447872#M112584</link>
      <description>&lt;P&gt;I have obtained the result ran by your code. Except&amp;nbsp;for&amp;nbsp;some of bottom,&amp;nbsp;all of them&amp;nbsp;are recorded in&amp;nbsp;the same column. do you have some advices about it please?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 17:58:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-large-csv-file-into-SAS-if-it-includes-the-extra/m-p/447872#M112584</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-03-22T17:58:36Z</dc:date>
    </item>
  </channel>
</rss>

