<?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: Data import: how to allow for &amp;quot;NA&amp;quot; values in a numeric variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856794#M338525</link>
    <description>&lt;P&gt;Concur with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;. Use a custom informat to catch expected special missing values. If other values appear, you'll still be notified.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Feb 2023 05:57:04 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-02-02T05:57:04Z</dc:date>
    <item>
      <title>Data import: how to allow for "NA" values in a numeric variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856765#M338514</link>
      <description>&lt;P&gt;I am trying to import data from a CSV file using data step infile command. One numeric variable occasionally has "NA" values. This generates error messages like "NOTE: Invalid data for XXX in line 317 45-46." This doesn't affect the imported dataset but is annoying.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to tell SAS to just keep "NA" as missing?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 23:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856765#M338514</guid>
      <dc:creator>xyxu</dc:creator>
      <dc:date>2023-02-01T23:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Data import: how to allow for "NA" values in a numeric variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856767#M338515</link>
      <description>&lt;P&gt;Have you checked your imported data because that will be what it is doing anyway - assigning a missing value because you can't store the characters "NA"&amp;nbsp; in a numeric variable.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 23:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856767#M338515</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-02-01T23:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Data import: how to allow for "NA" values in a numeric variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856768#M338516</link>
      <description>Yes, in the imported data, the value is indeed missing. I want SAS to stop generating error messages on data type mismatch in the import process.</description>
      <pubDate>Wed, 01 Feb 2023 23:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856768#M338516</guid>
      <dc:creator>xyxu</dc:creator>
      <dc:date>2023-02-01T23:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Data import: how to allow for "NA" values in a numeric variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856774#M338518</link>
      <description>&lt;P&gt;Why? Then you wont be aware of type mismatch errors in your imported data. Perhaps a better way would be to read the offending column as character then convert it to a new numeric column if it is not "NA". Then you can see exactly what gets imported and what gets converted.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 00:06:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856774#M338518</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-02-02T00:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: Data import: how to allow for "NA" values in a numeric variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856780#M338520</link>
      <description>Yeah the warning messages trigger my OCD.. Importing as char first works, but it is painful if there are many such columns.</description>
      <pubDate>Thu, 02 Feb 2023 00:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856780#M338520</guid>
      <dc:creator>xyxu</dc:creator>
      <dc:date>2023-02-02T00:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Data import: how to allow for "NA" values in a numeric variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856787#M338523</link>
      <description>&lt;P&gt;The best way is to use a proper INFORMAT for those fields. (Note: Do NOT use PROC IMPORT to read CSV files. You have no control over how the variables are named or defined.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue na (upcase)
  'NA'=.n
  other = [32.] 
;
run;

data test;
  input @1 good na. @1 bad ;
cards;
1
1.2
na
1E2
NA
.
;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;OBS     good     bad

 1       1.0      1.0
 2       1.2      1.2
 3        N        .
 4     100.0    100.0
 5        N        .
 6        .        .&lt;/PRE&gt;
&lt;P&gt;You could also just convert all of the NA strings to normal missing value (but beware if one of the fields is supposed to contain chemical compounds, it might convert all of the Sodium references to missing.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps best to create a NEW file so you can see what types of fixes were done.&lt;/P&gt;
&lt;P&gt;For short lines (&amp;lt;32K bytes) this should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile 'bad.txt' ;
  file 'good.txt';
  input ;
  _infile_ = tranwrd(cats(',',_infile_,','),',NA,',',.,');
  _infile_ = substrn(_infile_,2,length(_infile_)-2);
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do longer lines do it cell by cell.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 03:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856787#M338523</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-02T03:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Data import: how to allow for "NA" values in a numeric variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856794#M338525</link>
      <description>&lt;P&gt;Concur with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;. Use a custom informat to catch expected special missing values. If other values appear, you'll still be notified.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 05:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-import-how-to-allow-for-quot-NA-quot-values-in-a-numeric/m-p/856794#M338525</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-02T05:57:04Z</dc:date>
    </item>
  </channel>
</rss>

