<?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, while removing leading rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-while-removing-leading-rows/m-p/723238#M224401</link>
    <description>&lt;P&gt;Why are you using PROC IMPORT to read a delimited text file what has only four variables?&lt;/P&gt;
&lt;P&gt;Just write your own data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vacc_us ;
  infile "filepath" dsd truncover firstobs=5;
  input state :$20. LTC OneDose TwoDose;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Plus now you could read the timestamp from the second row if you wanted.&lt;/P&gt;</description>
    <pubDate>Wed, 03 Mar 2021 18:38:28 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-03-03T18:38:28Z</dc:date>
    <item>
      <title>PROC IMPORT of CSV file, while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-while-removing-leading-rows/m-p/723168#M224361</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to import a CSV file using this code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile="filepath"
        out=vacc_us
        dbms=csv
        replace;
		getnames=yes;
		datarow=5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the raw file looks like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="marleeakerson_0-1614784304746.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55397i9B0617E7111FF2AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="marleeakerson_0-1614784304746.png" alt="marleeakerson_0-1614784304746.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;So&amp;nbsp; want row 4 to be the column headers and the data to start at row 5. I essentially want rows 1,2 and 3 deleted. But the code I used doesn't quite work for this. I have tried using&amp;nbsp;&lt;CODE class=" language-sas"&gt;getnames=no; datarow=4;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&amp;nbsp;and&amp;nbsp;some&amp;nbsp;other&amp;nbsp;combinations&amp;nbsp;but&amp;nbsp;it&amp;nbsp;never&amp;nbsp;works&amp;nbsp;out&amp;nbsp;with&amp;nbsp;the&amp;nbsp;right column&amp;nbsp;headers.&amp;nbsp;Any&amp;nbsp;advice?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 15:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-while-removing-leading-rows/m-p/723168#M224361</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2021-03-03T15:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT of CSV file, while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-while-removing-leading-rows/m-p/723193#M224376</link>
      <description>&lt;P&gt;Try data row = 4 and getnames = yes and let us know if that works.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281255"&gt;@marleeakerson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to import a CSV file using this code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile="filepath"
        out=vacc_us
        dbms=csv
        replace;
		getnames=yes;
		datarow=5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the raw file looks like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="marleeakerson_0-1614784304746.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55397i9B0617E7111FF2AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="marleeakerson_0-1614784304746.png" alt="marleeakerson_0-1614784304746.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;So&amp;nbsp; want row 4 to be the column headers and the data to start at row 5. I essentially want rows 1,2 and 3 deleted. But the code I used doesn't quite work for this. I have tried using&amp;nbsp;&lt;CODE class=" language-sas"&gt;getnames=no; datarow=4;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&amp;nbsp;and&amp;nbsp;some&amp;nbsp;other&amp;nbsp;combinations&amp;nbsp;but&amp;nbsp;it&amp;nbsp;never&amp;nbsp;works&amp;nbsp;out&amp;nbsp;with&amp;nbsp;the&amp;nbsp;right column&amp;nbsp;headers.&amp;nbsp;Any&amp;nbsp;advice?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 16:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-while-removing-leading-rows/m-p/723193#M224376</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-03T16:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT of CSV file, while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-while-removing-leading-rows/m-p/723195#M224377</link>
      <description>&lt;P&gt;Thanks for replying!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, that does not work. The data looks like this after that switch:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="marleeakerson_0-1614789193996.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55398i1B13DD6E1CE0F7C6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="marleeakerson_0-1614789193996.png" alt="marleeakerson_0-1614789193996.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I need the data that is in line 1 to be the column headers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 16:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-while-removing-leading-rows/m-p/723195#M224377</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2021-03-03T16:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT of CSV file, while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-while-removing-leading-rows/m-p/723206#M224381</link>
      <description>How fixed is the file? Is it worth reading the file and writing it back out without the first 3 lines?&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;infile 'path to csv' firstobs=4;&lt;BR /&gt;file 'path to new csv';&lt;BR /&gt;input;&lt;BR /&gt;put _infile_;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Then import your new file? &lt;BR /&gt;&lt;BR /&gt;The code above is just skeleton/pseudocode, untested.</description>
      <pubDate>Wed, 03 Mar 2021 17:05:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-while-removing-leading-rows/m-p/723206#M224381</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-03T17:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT of CSV file, while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-while-removing-leading-rows/m-p/723218#M224388</link>
      <description>&lt;P&gt;My quick and dirty approach is to make a copy of the CSV, delete those first three rows before using proc import.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then copy the data step generated by the proc import from the log, paste into the editor and clean up the code (you are going to have some very ugly variable names that likely should be labels. I know I am not going to type a variable name like People_in_ltc_with_2_doses. I would name the variable(s) Dose1 and Dose2 and then use that text as the LABEL).&lt;/P&gt;
&lt;P&gt;You are also likely to have values that should be numeric come in as character because of the N/A values. I would create a custom informat to read the N/A as missing to avoid the next step of fixing values.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;proc format;
invalue myna (upcase)
'N/A', ' ' = .
other      = [best12.]
;
run;

data example;
   infile datalines dlm=',' dsd;
   informat value1 value2 myna.;
   input value1 value2;
datalines;
123,456
n/a,999
16,N/A
,888
;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Modify the codes Infile statement to point to the original, use the proper Firstobs option to read data at line 5.&lt;/P&gt;
&lt;P&gt;I am assuming you will have multiple files to read as time goes on and will need to repeat this. In which case you want to get away from proc import as quickly as possible.&lt;/P&gt;
&lt;P&gt;Change the infile and data set name for output of different files read.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 17:37:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-while-removing-leading-rows/m-p/723218#M224388</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-03T17:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT of CSV file, while removing leading rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-while-removing-leading-rows/m-p/723238#M224401</link>
      <description>&lt;P&gt;Why are you using PROC IMPORT to read a delimited text file what has only four variables?&lt;/P&gt;
&lt;P&gt;Just write your own data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vacc_us ;
  infile "filepath" dsd truncover firstobs=5;
  input state :$20. LTC OneDose TwoDose;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Plus now you could read the timestamp from the second row if you wanted.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 18:38:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-of-CSV-file-while-removing-leading-rows/m-p/723238#M224401</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-03T18:38:28Z</dc:date>
    </item>
  </channel>
</rss>

