<?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: Import CSV file with N/A in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-CSV-file-with-N-A/m-p/824207#M325464</link>
    <description>&lt;P&gt;There is no need to force SAS to GUESS how to read a file with only FOUR variables.&lt;/P&gt;
&lt;P&gt;Just write the data step yourself and you will have full control over how the variables are defined and how the N/A strings are handled.&lt;/P&gt;
&lt;P&gt;For example you could just use the ?? input modifier to have it ignore the fact that N/A is not a number.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  infile '\Downloads\333_12_44.csv' dsd truncover firstobs=2;
  input char1 :$10.  num1 price ?? datetime :anydtdtm. ;
  format datetime datetime26.5 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 19 Jul 2022 18:06:09 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-07-19T18:06:09Z</dc:date>
    <item>
      <title>Import CSV file with N/A</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-CSV-file-with-N-A/m-p/824205#M325463</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I want to import a csv file with 3 columns of the following format: Name, price, time(yyyy-mm-dd hh:mm:sss) and then extract date and time.&lt;/P&gt;
&lt;P&gt;One of the problem is price sometime has 'N/A' so I have to use guessingrows in my code.&lt;/P&gt;
&lt;P&gt;I wonder if there is anything else can be used since guessingrows might take too much time if I want to guessing=Max.&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ab,117.9,480751.0,2022-07-19 12:48:00.891313&lt;BR /&gt;AX,726.2398,16005050.0,2022-07-19 12:48:00.891313&lt;BR /&gt;MI,714.075,N/A,2022-07-19 12:48:00.891313&lt;/P&gt;
&lt;P&gt;AXxd,726.2398,16005050.0,2022-07-19 12:48:00.891313&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='\Downloads\333_12_44.csv' 
out=have replace; guessingrows=3000 ; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jul 2022 17:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-CSV-file-with-N-A/m-p/824205#M325463</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-07-19T17:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Import CSV file with N/A</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-CSV-file-with-N-A/m-p/824207#M325464</link>
      <description>&lt;P&gt;There is no need to force SAS to GUESS how to read a file with only FOUR variables.&lt;/P&gt;
&lt;P&gt;Just write the data step yourself and you will have full control over how the variables are defined and how the N/A strings are handled.&lt;/P&gt;
&lt;P&gt;For example you could just use the ?? input modifier to have it ignore the fact that N/A is not a number.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  infile '\Downloads\333_12_44.csv' dsd truncover firstobs=2;
  input char1 :$10.  num1 price ?? datetime :anydtdtm. ;
  format datetime datetime26.5 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jul 2022 18:06:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-CSV-file-with-N-A/m-p/824207#M325464</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-19T18:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: Import CSV file with N/A</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-CSV-file-with-N-A/m-p/824224#M325476</link>
      <description>&lt;P&gt;So much thanks, Tom.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 19:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-CSV-file-with-N-A/m-p/824224#M325476</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-07-19T19:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Import CSV file with N/A</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-CSV-file-with-N-A/m-p/824241#M325490</link>
      <description>&lt;P&gt;Another approach is to use a custom informat to read known problem values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format;
invalue pricena 
'N/A' = .N
other = [16.]
;
run;
data have ;
  infile datalines dlm=',' dsd;
  input char1 :$10.  num1 price :Pricena. datetime :anydtdtm. ;
  format datetime datetime26.5 ;
datalines;
Ab,117.9,480751.0,2022-07-19 12:48:00.891313
AX,726.2398,16005050.0,2022-07-19 12:48:00.891313
MI,714.075,N/A,2022-07-19 12:48:00.891313
AXxd,726.2398,16005050.0,2022-07-19 12:48:00.891313
;&lt;/PRE&gt;
&lt;P&gt;This creates an informat that will read N/A into a special missing value, .N, so that you can tell later that it was read as N/A.&lt;/P&gt;
&lt;P&gt;Coupled with the ?? informat modifier your data can tell you some things were handled gracefully and others not.&lt;/P&gt;
&lt;P&gt;Consider this example where someone had a data entry error or for some reason entered PDQ instead of price or N/A.&lt;/P&gt;
&lt;P&gt;We can tell from the data which missing value was which.&lt;/P&gt;
&lt;PRE&gt;data have2 ;
  infile datalines dlm=',' dsd;
  input char1 :$10.  num1 price ??:Pricena. datetime :anydtdtm. ;
  format datetime datetime26.5 ;
datalines;
Ab,117.9,480751.0,2022-07-19 12:48:00.891313
AX,726.2398,16005050.0,2022-07-19 12:48:00.891313
MI,714.075,N/A,2022-07-19 12:48:00.891313
AXxd,726.2398,PDQ,2022-07-19 12:48:00.891313
;&lt;/PRE&gt;
&lt;P&gt;The custom informat can be very helpful if you have multiple codes in what should be a numeric field. Consider the possibility of codes with meanings such as: period of record too short, not active yet, not longer valid or similar. Different special missings (up to 27, .A to .Z and ._) can allow you to answer questions about "how many no longer valid products were listed" that a simple missing applied to multiple codes will not. A custom format with the code meanings allows such reports to look nice. The values are still missing for any numeric calculation though such as mean price.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 21:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-CSV-file-with-N-A/m-p/824241#M325490</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-19T21:28:45Z</dc:date>
    </item>
  </channel>
</rss>

