<?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: SAS Import in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Import/m-p/479084#M123603</link>
    <description>&lt;P&gt;First thing is don't use PROC IMPORT for files that you already KNOW the format.&amp;nbsp; It will make guesses at how to define each variable. And it will make that guess for each file independently. Write your own data step to read the file.&amp;nbsp; You can even read all of them in one data step if you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To your question about how to read in a hyphen as meaning a missing value there here are some simple solutions.&lt;/P&gt;
&lt;P&gt;1) Just let SAS change it to missing for you.&amp;nbsp; You can add the ? or ?? modifiers to the INPUT (or INPUT() function) to suppress the errors.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile 'myfile.csv' dsd truncover firstobs=2 ;
  input volume :??comma. ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2) Read it as character and program around the value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile 'myfile.csv' dsd truncover firstobs=2 ;
  input volume_raw :$20. ;
  if volume_raw not in ('-',' ') then volume=input(volume_raw,comma32.) ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3) Make your own informat and use that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  invalue hyphen '-'=. other=[comma32.] ;
run;

data want ;
  infile 'myfile.csv' dsd truncover firstobs=2 ;
  input volume hyphen.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jul 2018 14:29:43 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-07-18T14:29:43Z</dc:date>
    <item>
      <title>SAS Import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Import/m-p/478976#M123580</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to import multiple CSV files (&amp;gt;500) into SAS and they all have the same variable formats.&lt;/P&gt;&lt;P&gt;There are a total of 16 variables of which 2 should be character and 14 should be numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried doing a proc import, however all fields were assigned to character by default.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then moved onto the data infile method and renamed the 14 variables from character ($4.) to best.&lt;/P&gt;&lt;P&gt;This is causing problems as the data for 4/14&amp;nbsp; variables contains a '-' where there is no number present.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example (one variable):&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Volume&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1,096,532&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;-&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;63,741&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;978,134&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I go about setting the numeric format? Is there another format besides 'best.' that can be used to accomodate for the '-'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS log shows:&lt;/P&gt;&lt;P&gt;NOTE: Invalid data for Volume in line 16 52-57&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 10:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Import/m-p/478976#M123580</guid>
      <dc:creator>PetePatel</dc:creator>
      <dc:date>2018-07-18T10:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Import/m-p/478996#M123590</link>
      <description>&lt;P&gt;Numbers like that are read with the comma. informat. You will only get a NOTE for invalid data for the hyphen. If you want to avoid that, do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input _number :$20.;
if _number ne '-' then number = input(_number,comma20.);
drop _number;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(it is recommended to make your code clean so that it does not throw NOTEs as mentioned above in normal operation)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;FONT size="2"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Edit: added a missing underline in the input function&lt;/FONT&gt; &lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 11:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Import/m-p/478996#M123590</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-18T11:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Import/m-p/479072#M123602</link>
      <description>&lt;P&gt;Using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options dsoptions=note2err;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;turns all unexpected notes into error messages. &lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 14:15:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Import/m-p/479072#M123602</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-07-18T14:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Import/m-p/479084#M123603</link>
      <description>&lt;P&gt;First thing is don't use PROC IMPORT for files that you already KNOW the format.&amp;nbsp; It will make guesses at how to define each variable. And it will make that guess for each file independently. Write your own data step to read the file.&amp;nbsp; You can even read all of them in one data step if you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To your question about how to read in a hyphen as meaning a missing value there here are some simple solutions.&lt;/P&gt;
&lt;P&gt;1) Just let SAS change it to missing for you.&amp;nbsp; You can add the ? or ?? modifiers to the INPUT (or INPUT() function) to suppress the errors.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile 'myfile.csv' dsd truncover firstobs=2 ;
  input volume :??comma. ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2) Read it as character and program around the value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile 'myfile.csv' dsd truncover firstobs=2 ;
  input volume_raw :$20. ;
  if volume_raw not in ('-',' ') then volume=input(volume_raw,comma32.) ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3) Make your own informat and use that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  invalue hyphen '-'=. other=[comma32.] ;
run;

data want ;
  infile 'myfile.csv' dsd truncover firstobs=2 ;
  input volume hyphen.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 14:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Import/m-p/479084#M123603</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-18T14:29:43Z</dc:date>
    </item>
  </channel>
</rss>

