<?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 -- 40-char field with only numbers is being converted to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-import-40-char-field-with-only-numbers-is-being-converted/m-p/809142#M319059</link>
    <description>&lt;P&gt;Not sure what EXCEL has to do with this.&amp;nbsp; A CSV file is just a text file.&lt;/P&gt;
&lt;P&gt;If you know the field is character why are you letting SAS have to GUESS how to read?&lt;/P&gt;
&lt;P&gt;You can read the text file yourself with a data step and you will have complete control over how the variables are defined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do want to use a tool to GUESS how to read the file then use one that knows numbers cannot be that large.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/csv2ds.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/csv2ds.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csv temp;
options parmcards=csv;

parmcards;
XREF,V1,V2
1111111573111111113288888888882704522560,AAA,123
;

%csv2ds(csv);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;11   +data fromcsv;
12   +  infile CSV dlm=',' dsd truncover firstobs=2 ;
13   +  length XREF $40 V1 $3 V2 8 ;
14   +  input XREF -- V2 ;
15   +run;

&lt;/PRE&gt;
&lt;P&gt;Plus it generates readable SAS code instead of the convoluted mess that PROC IMPORT generates.&lt;/P&gt;
&lt;PRE&gt;16    proc import datafile=csv dbms=csv out=import replace;
17    run;

18     /**********************************************************************
19     *   PRODUCT:   SAS
20     *   VERSION:   9.4
21     *   CREATOR:   External File Interface
22     *   DATE:      21APR22
23     *   DESC:      Generated SAS Datastep Code
24     *   TEMPLATE SOURCE:  (None Specified.)
25     ***********************************************************************/
26        data WORK.IMPORT    ;
27        %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
28        infile CSV delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
29           informat XREF best32. ;
30           informat V1 $3. ;
31           informat V2 best32. ;
32           format XREF best12. ;
33           format V1 $3. ;
34           format V2 best12. ;
35        input
36                    XREF
37                    V1  $
38                    V2
39        ;
40        if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
41        run;

&lt;/PRE&gt;</description>
    <pubDate>Fri, 22 Apr 2022 02:53:09 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-04-22T02:53:09Z</dc:date>
    <item>
      <title>proc import -- 40-char field with only numbers is being converted to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-import-40-char-field-with-only-numbers-is-being-converted/m-p/809138#M319055</link>
      <description>&lt;P&gt;I have a csv file that is being automatically export from an app.&amp;nbsp; The unique record identifier is a field called XREF.&amp;nbsp; In the app, it is a 40-character field but all the characters are digits (i.e.&amp;nbsp;1111111573111111113288888888882704522560).&amp;nbsp; Proc import thinks it's a numeric field and, because it's so large, it's doing that think where it truncates it to that E format (i.e.&amp;nbsp;1.11111157311E39).&amp;nbsp; &amp;nbsp;How do I get Excel to keep it as a character field?&amp;nbsp; &amp;nbsp;My program will be going into production so there will be no manual import (i.e through Import Wizard) nor the opportunity to manipulate the csv file before importing.&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="Anna_dlC_0-1650562973503.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70686iA0F8FEB811E26D20/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Anna_dlC_0-1650562973503.png" alt="Anna_dlC_0-1650562973503.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 17:44:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-import-40-char-field-with-only-numbers-is-being-converted/m-p/809138#M319055</guid>
      <dc:creator>Anna_dlC</dc:creator>
      <dc:date>2022-04-21T17:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: proc import -- 40-char field with only numbers is being converted to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-import-40-char-field-with-only-numbers-is-being-converted/m-p/809140#M319057</link>
      <description>&lt;P&gt;Simple solution: do not use PROC IMPORT, but write the data step yourself.&lt;/P&gt;
&lt;P&gt;Start with the code that was created by PROC IMPORT (take it from the log), and adapt it to your needs.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 17:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-import-40-char-field-with-only-numbers-is-being-converted/m-p/809140#M319057</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-21T17:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: proc import -- 40-char field with only numbers is being converted to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-import-40-char-field-with-only-numbers-is-being-converted/m-p/809142#M319059</link>
      <description>&lt;P&gt;Not sure what EXCEL has to do with this.&amp;nbsp; A CSV file is just a text file.&lt;/P&gt;
&lt;P&gt;If you know the field is character why are you letting SAS have to GUESS how to read?&lt;/P&gt;
&lt;P&gt;You can read the text file yourself with a data step and you will have complete control over how the variables are defined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do want to use a tool to GUESS how to read the file then use one that knows numbers cannot be that large.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/csv2ds.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/csv2ds.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csv temp;
options parmcards=csv;

parmcards;
XREF,V1,V2
1111111573111111113288888888882704522560,AAA,123
;

%csv2ds(csv);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;11   +data fromcsv;
12   +  infile CSV dlm=',' dsd truncover firstobs=2 ;
13   +  length XREF $40 V1 $3 V2 8 ;
14   +  input XREF -- V2 ;
15   +run;

&lt;/PRE&gt;
&lt;P&gt;Plus it generates readable SAS code instead of the convoluted mess that PROC IMPORT generates.&lt;/P&gt;
&lt;PRE&gt;16    proc import datafile=csv dbms=csv out=import replace;
17    run;

18     /**********************************************************************
19     *   PRODUCT:   SAS
20     *   VERSION:   9.4
21     *   CREATOR:   External File Interface
22     *   DATE:      21APR22
23     *   DESC:      Generated SAS Datastep Code
24     *   TEMPLATE SOURCE:  (None Specified.)
25     ***********************************************************************/
26        data WORK.IMPORT    ;
27        %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
28        infile CSV delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
29           informat XREF best32. ;
30           informat V1 $3. ;
31           informat V2 best32. ;
32           format XREF best12. ;
33           format V1 $3. ;
34           format V2 best12. ;
35        input
36                    XREF
37                    V1  $
38                    V2
39        ;
40        if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
41        run;

&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Apr 2022 02:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-import-40-char-field-with-only-numbers-is-being-converted/m-p/809142#M319059</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-22T02:53:09Z</dc:date>
    </item>
  </channel>
</rss>

