<?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: Importing CSV file with datafile in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-file-with-datafile/m-p/808671#M318867</link>
    <description>&lt;P&gt;To make it easier you can use syntax that means to read the same variable multiple times.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input want1 3*dummy want2 ...  ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 19 Apr 2022 19:52:38 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-04-19T19:52:38Z</dc:date>
    <item>
      <title>Importing CSV file with datafile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-file-with-datafile/m-p/808647#M318858</link>
      <description>&lt;P&gt;I'm trying to import csv files with a datafile step. There are many rows in the csv file; I'm interested to get only a few. However, when I run the following code, I get the first few rows -- not the ones I'm looking for. Any help is appreciated:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data master_10;&lt;BR /&gt;%let _EFIERR_ = 0;&lt;BR /&gt;infile 'C:\Users\bmf.bm1812.csv'&lt;BR /&gt;delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;&lt;/P&gt;&lt;P&gt;informat EIN best32. ; informat SEC_NAME $33. ; informat NAME $60. ;&lt;BR /&gt;informat STATE $2. ; informat nteeFinal $5. ; informat NTEECC $4. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;format EIN best12. ; format SEC_NAME $33. ; format NAME $60. ;&lt;BR /&gt;format STATE $2. ; format nteeFinal $5. ; format NTEECC $4. ;&lt;BR /&gt;&lt;BR /&gt;input EIN SEC_NAME $ NAME $ STATE $ nteeFinal $&lt;BR /&gt;NTEECC $;&lt;/P&gt;&lt;P&gt;if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2022 18:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-file-with-datafile/m-p/808647#M318858</guid>
      <dc:creator>92568466</dc:creator>
      <dc:date>2022-04-19T18:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Importing CSV file with datafile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-file-with-datafile/m-p/808655#M318860</link>
      <description>&lt;P&gt;Why would that code not read all of the lines from the CSV file?&amp;nbsp; What do the notes in the SAS log say?&amp;nbsp; It should say how many lines read, and the min and max length of the lines. It should say how many observations were written to the dataset.&amp;nbsp; There might be other notes also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How did you create that ugly code?&amp;nbsp; It looks like the code generated by PROC IMPORT.&lt;/P&gt;
&lt;P&gt;If you really only have 6 variables just write your own data step to read the file and skip the guessing procedure.&amp;nbsp; None of the variables your code describes need to have an informat nor a format attached.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bm1812 ;
  infile 'C:\Users\bmf.bm1812.csv' dsd firstobs=2 truncover ;
  length EIN 8 SEC_NAME $33 NAME $60 STATE $2 nteeFinal $5 NTEECC $4 ;
  input EIN -- NTEECC ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't want to read all of the lines then which lines do you want to read?&amp;nbsp; In general you will have to read all of the lines in order to decide which ones to write out to the dataset.&amp;nbsp; Unless you just want to read the top nn lines from the file.&amp;nbsp; In which case add the OBS= option to the INFILE statement in addition to the FIRSTOBS= option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2022 18:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-file-with-datafile/m-p/808655#M318860</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-19T18:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: Importing CSV file with datafile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-file-with-datafile/m-p/808661#M318863</link>
      <description>&lt;P&gt;My bad; I meant columns, not rows. I have many columns (variables) in the csv file, but I need only these. I can't get these columns using the code. It gives me first few variables, instead of the selected ones.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2022 19:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-file-with-datafile/m-p/808661#M318863</guid>
      <dc:creator>92568466</dc:creator>
      <dc:date>2022-04-19T19:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Importing CSV file with datafile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-file-with-datafile/m-p/808662#M318864</link>
      <description>There is no error in the log though. A file is created.</description>
      <pubDate>Tue, 19 Apr 2022 19:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-file-with-datafile/m-p/808662#M318864</guid>
      <dc:creator>92568466</dc:creator>
      <dc:date>2022-04-19T19:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Importing CSV file with datafile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-file-with-datafile/m-p/808664#M318866</link>
      <description>&lt;P&gt;The columns in a csv file are sequential, so you need to read over the columns you do not want. I usually define a character variable called dummy, which I use repeatedly to read the unwanted columns and DROP it from the dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dara want;
infile "...." dlm="," dsd truncover firstobs=2;
length
  want1 ....
  want2 ...
  .....
  dummy $1
;
input
  want1
  dummy
  dummy
  dummy
  want2
  .....
;
drop dummy;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Apr 2022 08:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-file-with-datafile/m-p/808664#M318866</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-26T08:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Importing CSV file with datafile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-file-with-datafile/m-p/808671#M318867</link>
      <description>&lt;P&gt;To make it easier you can use syntax that means to read the same variable multiple times.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input want1 3*dummy want2 ...  ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Apr 2022 19:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-file-with-datafile/m-p/808671#M318867</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-19T19:52:38Z</dc:date>
    </item>
  </channel>
</rss>

