<?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 and NOT use GUESSINGROWS to determine field widths? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/685623#M207965</link>
    <description>&lt;P&gt;See method 2 &lt;A href="https://www.sascrunch.com/importing-csv-files.html" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Tue, 22 Sep 2020 08:54:54 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-09-22T08:54:54Z</dc:date>
    <item>
      <title>How to import a large .csv file and NOT use GUESSINGROWS to determine field widths?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/685589#M207948</link>
      <description>&lt;P&gt;My .csv file has 50+ million records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The maximum widths of each field (Excel column) are known (to me).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the early records in the .csv file contain fewer characters in some fields than in later records (much later) -- and SAS is truncating data when importing those later records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to specify all the field widths in the PROC IMPORT syntax and avoid GUESSINGROWS completely?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or, is there another way to input the .csv file in one pass and not lose data?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to SAS, so my terms may be off.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 06:21:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/685589#M207948</guid>
      <dc:creator>sasmhe</dc:creator>
      <dc:date>2020-09-22T06:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a large .csv file and NOT use GUESSINGROWS to determine field widths?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/685591#M207949</link>
      <description>&lt;P&gt;Since you have a description of the columns, just write the DATA step for the import yourself.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 06:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/685591#M207949</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-22T06:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a large .csv file and NOT use GUESSINGROWS to determine field widths?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/685623#M207965</link>
      <description>&lt;P&gt;See method 2 &lt;A href="https://www.sascrunch.com/importing-csv-files.html" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 08:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/685623#M207965</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-22T08:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a large .csv file and NOT use GUESSINGROWS to determine field widths?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/685923#M208064</link>
      <description>&lt;P&gt;Both of the above commenters have given good advice:&amp;nbsp; Code a Data step.&amp;nbsp; Let me suggest some alternatives to generate the code:&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp; You can use Proc Import to generate the Data step.&amp;nbsp; Proc import generates a Data step under the covers, and you can take that code from the log as the basis for your Data step.&amp;nbsp; It saves you from having to write everything from scratch.&amp;nbsp; The second set of code below was generated by a Proc Import.&amp;nbsp; I'm putting the Proc Import code last because I actually prefer my next method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp; Perhaps even better, if you have Enterprise Guide available to you, you can drag the csv file onto the Process Flow and right click it.&amp;nbsp; Up will come a pop-up on which one of the choices is "Import."&amp;nbsp; A dialog then opens the result of which is the generated Data step below.&amp;nbsp; If I don't like a particular length or definition, the code is mine to modify as I please.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the Data step code generated by SAS Enterprise Guide:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* --------------------------------------------------------------------
   Code generated by a SAS task
   
   Generated on Tuesday, September 22, 2020 at 8:34:49 PM
   By task:     Import Data Wizard
   
   Source file:
   I:\commercial\development\Core_Datasets\pgm\Related\ACTV_MBR_SRVC_P
   OP_Mismatch.txt
   Server:      Local File System
   
   Output data: WORK.ACTV_MBR_SRVC_POP_Mismatch
   Server:      Local
   -------------------------------------------------------------------- */

DATA WORK.ACTV_MBR_SRVC_POP_Mismatch;
    LENGTH
        Actv_MBR_GLB_ID  $ 13
        GbID_MBR_GLB_ID  $ 13
        Actv_MBR_ID      $ 23
        GbID_MBR_ID      $ 23
        Srvc_MBR_ID      $ 23
        Srvc_MBR_MOD_ID    8
        GbID_MBR_MOD_ID    8
        GbID_D_MBR_SK      8
        Srvc_D_MBR_SK      8
        Actv_active_mbrs $ 1
        MBR_SRVC_POP_CD  $ 19
        MBR_SRVC_POP_IND $ 1 ;
    FORMAT
        Actv_MBR_GLB_ID  $CHAR13.
        GbID_MBR_GLB_ID  $CHAR13.
        Actv_MBR_ID      $CHAR23.
        GbID_MBR_ID      $CHAR23.
        Srvc_MBR_ID      $CHAR23.
        Srvc_MBR_MOD_ID  BEST8.
        GbID_MBR_MOD_ID  BEST8.
        GbID_D_MBR_SK    BEST8.
        Srvc_D_MBR_SK    BEST8.
        Actv_active_mbrs $CHAR1.
        MBR_SRVC_POP_CD  $CHAR19.
        MBR_SRVC_POP_IND $CHAR1. ;
    INFORMAT
        Actv_MBR_GLB_ID  $CHAR13.
        GbID_MBR_GLB_ID  $CHAR13.
        Actv_MBR_ID      $CHAR23.
        GbID_MBR_ID      $CHAR23.
        Srvc_MBR_ID      $CHAR23.
        Srvc_MBR_MOD_ID  BEST8.
        GbID_MBR_MOD_ID  BEST8.
        GbID_D_MBR_SK    BEST8.
        Srvc_D_MBR_SK    BEST8.
        Actv_active_mbrs $CHAR1.
        MBR_SRVC_POP_CD  $CHAR19.
        MBR_SRVC_POP_IND $CHAR1. ;
    INFILE 'I:\commercial\development\Core_Datasets\pgm\Related\ACTV_MBR_SRVC_POP_Mismatch.txt'
        LRECL=32767
        FIRSTOBS=2
        ENCODING="WLATIN1"
        DLM='09'x
        MISSOVER
        DSD ;
    INPUT
        Actv_MBR_GLB_ID  : $CHAR13.
        GbID_MBR_GLB_ID  : $CHAR13.
        Actv_MBR_ID      : $CHAR23.
        GbID_MBR_ID      : $CHAR23.
        Srvc_MBR_ID      : $CHAR23.
        Srvc_MBR_MOD_ID  : ?? BEST8.
        GbID_MBR_MOD_ID  : ?? BEST8.
        GbID_D_MBR_SK    : ?? BEST8.
        Srvc_D_MBR_SK    : ?? BEST8.
        Actv_active_mbrs : $CHAR1.
        MBR_SRVC_POP_CD  : $CHAR19.
        MBR_SRVC_POP_IND : $CHAR1. ;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here's the code generated by a Proc Import.&amp;nbsp; I list the Proc Import first and immediately following is the code it generated which I cut and paste in from the log.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc  IMPORT	
	DATAFILE='I:\commercial\development\Core_Datasets\pgm\Related\ACTV_MBR_SRVC_POP_Mismatch.txt'
	OUT	=	WORK.ACTV_MBR_SRVC_POP_MISMATCH2
	DBMS=DLM
	REPLACE
	;
	DELIMITER='09'X;
	DATAROW=2;
	GUESSINGROWS=20000;
RUN;

 /**********************************************************************
 *   PRODUCT:   SAS
 *   VERSION:   9.4
 *   CREATOR:   External File Interface
 *   DATE:      22SEP20
 *   DESC:      Generated SAS Datastep Code
 *   TEMPLATE SOURCE:  (None Specified.)
 ***********************************************************************/
    data WORK.ACTV_MBR_SRVC_POP_MISMATCH2    ;
    infile 'I:\commercial\development\Core_Datasets\pgm\Related\ACTV_MBR_SRVC_POP_Mismatch.txt' delimiter='09'x
MISSOVER DSD lrecl=32767 firstobs=2 ;
       informat Actv_MBR_GLB_ID $13. ;
       informat GbID_MBR_GLB_ID $13. ;
       informat Actv_MBR_ID $23. ;
       informat GbID_MBR_ID $23. ;
       informat Srvc_MBR_ID $23. ;
       informat Srvc_MBR_MOD_ID best32. ;
       informat GbID_MBR_MOD_ID best32. ;
       informat GbID_D_MBR_SK best32. ;
       informat Srvc_D_MBR_SK best32. ;
       informat Actv_active_mbrs $1. ;
       informat MBR_SRVC_POP_CD $19. ;
       informat MBR_SRVC_POP_IND $1. ;
       format Actv_MBR_GLB_ID $13. ;
       format GbID_MBR_GLB_ID $13. ;
       format Actv_MBR_ID $23. ;
       format GbID_MBR_ID $23. ;
       format Srvc_MBR_ID $23. ;
       format Srvc_MBR_MOD_ID best12. ;
       format GbID_MBR_MOD_ID best12. ;
       format GbID_D_MBR_SK best12. ;
       format Srvc_D_MBR_SK best12. ;
       format Actv_active_mbrs $1. ;
       format MBR_SRVC_POP_CD $19. ;
       format MBR_SRVC_POP_IND $1. ;
    input
                Actv_MBR_GLB_ID  $
                GbID_MBR_GLB_ID  $
                Actv_MBR_ID  $
                GbID_MBR_ID  $
                Srvc_MBR_ID  $
                Srvc_MBR_MOD_ID
                GbID_MBR_MOD_ID
                GbID_D_MBR_SK
                Srvc_D_MBR_SK
                Actv_active_mbrs  $
                MBR_SRVC_POP_CD  $
                MBR_SRVC_POP_IND  $
    ;
    run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Sep 2020 15:31:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/685923#M208064</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-23T15:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a large .csv file and NOT use GUESSINGROWS to determine field widths?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/686060#M208119</link>
      <description>&lt;P&gt;Hi ChrisNZ,&lt;/P&gt;&lt;P&gt;Method 2 in the &lt;A href="https://www.sascrunch.com/importing-csv-files.html" target="_self"&gt;link&lt;/A&gt; you sent worked perfectly.&lt;/P&gt;&lt;P&gt;Thanks very much,&lt;/P&gt;&lt;P&gt;seamhe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 14:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/686060#M208119</guid>
      <dc:creator>sasmhe</dc:creator>
      <dc:date>2020-09-23T14:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a large .csv file and NOT use GUESSINGROWS to determine field widths?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/686070#M208125</link>
      <description>&lt;P&gt;Hi jimbarbour,&lt;/P&gt;&lt;P&gt;The Data Step method worked for me.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your response, and I've made a note of your alternative suggestions.&lt;/P&gt;&lt;P&gt;-- seamhe&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 14:49:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/686070#M208125</guid>
      <dc:creator>sasmhe</dc:creator>
      <dc:date>2020-09-23T14:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to import a large .csv file and NOT use GUESSINGROWS to determine field widths?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/686071#M208126</link>
      <description>&lt;P&gt;Thanks, KurtBremer.&lt;/P&gt;&lt;P&gt;The Data Step method worked fine.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 14:51:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-import-a-large-csv-file-and-NOT-use-GUESSINGROWS-to/m-p/686071#M208126</guid>
      <dc:creator>sasmhe</dc:creator>
      <dc:date>2020-09-23T14:51:00Z</dc:date>
    </item>
  </channel>
</rss>

