<?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: PROC IMPORT of CSV file with semicolon delimiter and while removing leading rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821778#M324454</link>
    <description>&lt;P&gt;Don't let PROC IMPORT mess up your data when reading text files. Write the data step yourself with FIRSTOBS=3 in the INFILE statement.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Jul 2022 05:58:31 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-07-06T05:58:31Z</dc:date>
    <item>
      <title>PROC IMPORT of CSV file with semicolon delimiter and while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821763#M324442</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hoping someone can help and correct the logic I am using. THank you in advance &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trying to import a csv file that is separated by semicolon and the field names start on row 2 and data starts row 3&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;csv file shoes_startrow.csv (attached):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sufiya_0-1657061780425.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72967iE1EDDE6E6D3F8CF2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sufiya_0-1657061780425.png" alt="sufiya_0-1657061780425.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;syntax:&lt;/P&gt;&lt;P&gt;proc import datafile="C:\Users\Other Request\shoes_startrow.csv"&lt;BR /&gt;out=Shoe_File&lt;BR /&gt;dbms=csv replace;&lt;BR /&gt;GETNAMES=NO;&lt;BR /&gt;DELIMITER=';';&lt;BR /&gt;DATAROW=2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sufiya_1-1657063157492.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72968iB518F457E84DCCAE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sufiya_1-1657063157492.png" alt="sufiya_1-1657063157492.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;want:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Region&lt;/TD&gt;&lt;TD&gt;Product&lt;/TD&gt;&lt;TD&gt;Subsidiary&lt;/TD&gt;&lt;TD&gt;Stores&lt;/TD&gt;&lt;TD&gt;Sales&lt;/TD&gt;&lt;TD&gt;Inventory&lt;/TD&gt;&lt;TD&gt;Returns&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Africa&lt;/TD&gt;&lt;TD&gt;Boot&lt;/TD&gt;&lt;TD&gt;Addis Ababa&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;$29,761&lt;/TD&gt;&lt;TD&gt;$191,821&lt;/TD&gt;&lt;TD&gt;$769&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Africa&lt;/TD&gt;&lt;TD&gt;Men's Casual&lt;/TD&gt;&lt;TD&gt;Addis Ababa&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;$67,242&lt;/TD&gt;&lt;TD&gt;$118,036&lt;/TD&gt;&lt;TD&gt;$2,284&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Africa&lt;/TD&gt;&lt;TD&gt;Men's Dress&lt;/TD&gt;&lt;TD&gt;Addis Ababa&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;$76,793&lt;/TD&gt;&lt;TD&gt;$136,273&lt;/TD&gt;&lt;TD&gt;$2,433&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Africa&lt;/TD&gt;&lt;TD&gt;Sandal&lt;/TD&gt;&lt;TD&gt;Addis Ababa&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;$62,819&lt;/TD&gt;&lt;TD&gt;$204,284&lt;/TD&gt;&lt;TD&gt;$1,861&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Africa&lt;/TD&gt;&lt;TD&gt;Slipper&lt;/TD&gt;&lt;TD&gt;Addis Ababa&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;$68,641&lt;/TD&gt;&lt;TD&gt;$279,795&lt;/TD&gt;&lt;TD&gt;$1,771&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Africa&lt;/TD&gt;&lt;TD&gt;Sport Shoe&lt;/TD&gt;&lt;TD&gt;Addis Ababa&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;$1,690&lt;/TD&gt;&lt;TD&gt;$16,634&lt;/TD&gt;&lt;TD&gt;$79&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Africa&lt;/TD&gt;&lt;TD&gt;Women's Casual&lt;/TD&gt;&lt;TD&gt;Addis Ababa&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;$51,541&lt;/TD&gt;&lt;TD&gt;$98,641&lt;/TD&gt;&lt;TD&gt;$940&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Africa&lt;/TD&gt;&lt;TD&gt;Women's Dress&lt;/TD&gt;&lt;TD&gt;Addis Ababa&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;$108,942&lt;/TD&gt;&lt;TD&gt;$311,017&lt;/TD&gt;&lt;TD&gt;$3,233&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 06 Jul 2022 02:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821763#M324442</guid>
      <dc:creator>sufiya</dc:creator>
      <dc:date>2022-07-06T02:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT of CSV file with semicolon delimiter and while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821765#M324444</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile="C:\Users\Other Request\shoes_startrow.csv"
out=Shoe_File
dbms=csv replace;
GETNAMES=YES;
DELIMITER=';';
DATAROW=3;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jul 2022 02:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821765#M324444</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-07-06T02:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT of CSV file with semicolon delimiter and while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821778#M324454</link>
      <description>&lt;P&gt;Don't let PROC IMPORT mess up your data when reading text files. Write the data step yourself with FIRSTOBS=3 in the INFILE statement.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 05:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821778#M324454</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-06T05:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT of CSV file with semicolon delimiter and while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821786#M324456</link>
      <description>&lt;P&gt;This would be the code to read your csv file:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile "C:\Users\Other Request\shoes_startrow.csv" dlm=";" dsd firstobs=3 truncover;
input
  region :$25.
  product :$14.
  subsidiary :$12.
  stores
  sales :dollar12.
  inventory :dollar12.
  returns :dollar12.
;
format
  sales :dollar12.
  inventory :dollar12.
  returns :dollar12.
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jul 2022 08:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821786#M324456</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-06T08:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT of CSV file with semicolon delimiter and while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821787#M324457</link>
      <description>&lt;P&gt;PS in order to supply an example of your data which we can use for testing, either attach the csv to your post, or open it with a text editor and copy/paste a sufficient number of lines into a window opened with this button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Do not post data as pictures, especially not as screenshots from Excel.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 08:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821787#M324457</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-06T08:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT of CSV file with semicolon delimiter and while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821817#M324472</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; - sorry I thought I did attached the csv file.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 12:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821817#M324472</guid>
      <dc:creator>sufiya</dc:creator>
      <dc:date>2022-07-06T12:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT of CSV file with semicolon delimiter and while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821828#M324476</link>
      <description>&lt;DIV class=""&gt;&lt;SPAN&gt;Hi&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_blank" rel="noopener"&gt;Kurt_Bremser&lt;/A&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;this works but I end up with a blank/null last row - is there anyway to remove the row if all fields are null?&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;thank you,&lt;/DIV&gt;&lt;DIV class=""&gt;Sof&lt;/DIV&gt;</description>
      <pubDate>Wed, 06 Jul 2022 13:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821828#M324476</guid>
      <dc:creator>sufiya</dc:creator>
      <dc:date>2022-07-06T13:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT of CSV file with semicolon delimiter and while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821835#M324480</link>
      <description>&lt;P&gt;That file is even more messed up that you originally suggested.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;11   data _null_;
12     infile "c:\downloads\shoes_startrow.csv";
13     input;
14     list;
15   run;

NOTE: The infile "c:\downloads\shoes_startrow.csv" is:
      Filename=c:\downloads\shoes_startrow.csv,
      RECFM=V,LRECL=32767,File Size (bytes)=30195,
      Last Modified=06Jul2022:09:28:09,
      Create Time=06Jul2022:09:28:09

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
1         xxxxx;;;;;;,,,,,, 17
2         Region;Product;Subsidiary;Stores;Sales;Inventory;Returns,,,,,, 62
3         "Africa;Boot;Addis Ababa;12;""$29;761"";""$191;821"";$769",,,,,, 64
4         "Africa;Men's Casual;Addis Ababa;4;""$67;242"";""$118;036"";""$2;284""",,,,,, 77
5         "Africa;Men's Dress;Addis Ababa;7;""$76;793"";""$136;273"";""$2;433""",,,,,, 76
6         "Africa;Sandal;Addis Ababa;10;""$62;819"";""$204;284"";""$1;861""",,,,,, 72&lt;/PRE&gt;
&lt;P&gt;In addition the the extra line at the top and the extra line at the bottom every line is corrupted.&amp;nbsp; Instead of having 7 values separated by semicolons most of the lines have one value followed by bunch of commas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure this is your ORIGINAL file?&amp;nbsp; Or did you accidentally let EXCEL automatically open the CSV file and then save that modified version of the file back as a CSV file?&amp;nbsp; In general you should never let EXCEL automatically open a CSV file (other than for simple exploring) as it will make decisions about how the convert the text into a spreadsheet including changing some of the "cell" values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the file is like this then first convert it to a real CSV file and then read that.&amp;nbsp; You could remove the header and trailer lines at the same time.&amp;nbsp; Since the resulting file is not using commas as the delimiter let's not use CSV as the extension on the file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename have 'myfile.csv';
filename want 'myfile_fixed.txt';
data _null_;
   infile have dsd truncover  end=eof;
   file want;
   input line :$1000. ;
   if _n_=1 or eof then putlog _n_= _infile_;
   else put line;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 13:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/821835#M324480</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-06T13:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT of CSV file with semicolon delimiter and while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/822067#M324583</link>
      <description>&lt;P&gt;So your file is not a semicolon-separated pseudo-csv (as created by Excel), but a real comma separated volume with all the information in the first column, which is enclosed in double quotes, is internally separated by semicolons and also contains double quotes. And some of the numbers have semicolons instead of commas. In short, an unbelievable mess. Who threw this piece of computing crap at you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, this code reads your file successfully, but I include it only to show what SAS is capable of. You should not try to make sense out of this file, return it to sender, with a solid nastygram attached to it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile "~/shoes_startrow.csv" dlm="," dsd firstobs=3 truncover;
length
  region $25
  product $14
  subsidiary $12
  stores 8
  sales 8
  inventory 8
  returns 8
;
format
  sales
  inventory
  returns dollar12.
;
input line :$100.;
if not index(line,"row count");
region = scan(line,1,";");
product = scan(line,2,";");
subsidiary = scan(line,3,";");
stores = input(scan(line,4,";"),best.);
_sales = compress(scan(line,5,";") !! scan(line,6,";"),'"');
sales = input(_sales,dollar20.);
_inventory = compress(scan(line,7,";") !! scan(line,8,";"),'"');
inventory = input(_inventory,dollar20.);
_returns = compress(scan(line,9,";") !! scan(line,10,";"),'"');
returns = input(_returns,dollar20.);
drop _:  line;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jul 2022 14:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-with-semicolon-delimiter-and-while/m-p/822067#M324583</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-07T14:34:07Z</dc:date>
    </item>
  </channel>
</rss>

