<?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: Read from a text file in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/308689#M1438</link>
    <description>&lt;P&gt;If you want a column to be numeric, but have non-numeric data in the input stream that signals a missing value, your best choice is to read into a temporary character variable and conditionally convert from that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ....;
infile .....;
length ...... _age $3 age 3 ......;
input ..... _age .....;
if _age = 'NA'
then age = .;
else age = input(_age,3.);
drop _age;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 02 Nov 2016 07:18:43 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-11-02T07:18:43Z</dc:date>
    <item>
      <title>Read from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/308663#M1430</link>
      <description>&lt;P&gt;Hi, i have trouble importing my text files, my output does not get the same as my lecure given.&lt;/P&gt;&lt;P&gt;Bellow are my codes and files attachment.&lt;/P&gt;&lt;P&gt;Thnks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data ass.titaniccsv;&lt;BR /&gt;length row_names 3 pclass $3 survived 3 name $82 age 3&lt;BR /&gt;embarked $3 home_dest $70 room $5 ticket $20 boat $3 sex $10;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;infile '/home/titanic.txt' dlm=',' dsd;&lt;BR /&gt;input row_names pclass $ survived name ~ $82. age&lt;BR /&gt;embarked $ home_dest $ room $ ticket $ boat $ sex $;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 04:47:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/308663#M1430</guid>
      <dc:creator>yewkeong</dc:creator>
      <dc:date>2016-11-02T04:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Read from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/308665#M1431</link>
      <description>&lt;P&gt;Any errors in your log?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 05:02:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/308665#M1431</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-02T05:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Read from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/308669#M1432</link>
      <description>&lt;P&gt;no error, just warning.&amp;nbsp;&lt;/P&gt;&lt;P&gt;the invalid data appeared every line.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasNote"&gt;NOTE: Invalid data for age in line 73 41-42.&lt;/DIV&gt;&lt;DIV class="sasWarning"&gt;WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;73 "72","1st",0,"Crafton, Mr John Bertram",NA,"Southampton","Roachdale, IN","","","","male" 88&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;row_names=72 pclass=1st survived=0 name="Crafton, Mr John Bertram" age=. embarked=Sou home_dest=Roachdale, IN room= ticket= boat=&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;sex=male _ERROR_=1 _N_=73&lt;/DIV&gt;</description>
      <pubDate>Wed, 02 Nov 2016 05:15:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/308669#M1432</guid>
      <dc:creator>yewkeong</dc:creator>
      <dc:date>2016-11-02T05:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: Read from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/308671#M1433</link>
      <description>&lt;P&gt;Your code between this and your other question differ.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest using proc import and set GUESSINGROWS to the number of observation. The code to read the data will be in your log. Use that to compare t your current code to find the errors.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 05:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/308671#M1433</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-02T05:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: Read from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/308685#M1435</link>
      <description>&lt;P&gt;Just to relate to the error message:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NOTE: Invalid data for age in line 73 41-42.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in your code you defined: &amp;nbsp; &lt;STRONG&gt;length ... age 3 ... &amp;nbsp;&lt;/STRONG&gt;whichs means that a &lt;STRONG&gt;numeric &lt;/STRONG&gt;data is expected&lt;/P&gt;
&lt;P&gt;the input value for age in line 73 (and many others) is &lt;STRONG&gt;NA&amp;nbsp;&lt;/STRONG&gt;that is an &lt;STRONG&gt;alpha&lt;/STRONG&gt;numeric data,&lt;/P&gt;
&lt;P&gt;and as such it is invalid, therfore output is:&amp;nbsp;&lt;STRONG&gt;age=.&amp;nbsp;&lt;/STRONG&gt;which means age has &lt;STRONG&gt;missing&lt;/STRONG&gt; value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your first post you wrote:&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;my output does not get the same as my lecure given.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;What have you been given ? Are there other discompatibilities ?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 06:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/308685#M1435</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-02T06:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: Read from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/308689#M1438</link>
      <description>&lt;P&gt;If you want a column to be numeric, but have non-numeric data in the input stream that signals a missing value, your best choice is to read into a temporary character variable and conditionally convert from that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ....;
infile .....;
length ...... _age $3 age 3 ......;
input ..... _age .....;
if _age = 'NA'
then age = .;
else age = input(_age,3.);
drop _age;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Nov 2016 07:18:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/308689#M1438</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-02T07:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: Read from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/309060#M1440</link>
      <description>&lt;P&gt;alrigh noted with thanks!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 15:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/309060#M1440</guid>
      <dc:creator>yewkeong</dc:creator>
      <dc:date>2016-11-03T15:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Read from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/309062#M1441</link>
      <description>oh i see! didnt notice my age variable having an alpha data. Thanks man!&lt;BR /&gt;&lt;BR /&gt;the output must be the same as the text files that i attached</description>
      <pubDate>Thu, 03 Nov 2016 15:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/309062#M1441</guid>
      <dc:creator>yewkeong</dc:creator>
      <dc:date>2016-11-03T15:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Read from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/309080#M1442</link>
      <description>hey it works! but can u explain more details for me about this code? i dont really understand y must be two variables. At first store inside the character variables which is _age $3, if got 'NA' then set the numeric variables equals to missing value. if is not 'NA' the convert the _age into numeric? is it??&lt;BR /&gt;&lt;BR /&gt;i'm sorry i very new aboout sas studio. =')</description>
      <pubDate>Thu, 03 Nov 2016 16:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/309080#M1442</guid>
      <dc:creator>yewkeong</dc:creator>
      <dc:date>2016-11-03T16:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Read from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/309082#M1443</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/107885"&gt;@yewkeong&lt;/a&gt; wrote:&lt;BR /&gt;hey it works! but can u explain more details for me about this code? i dont really understand y must be two variables. At first store inside the character variables which is _age $3, if got 'NA' then set the numeric variables equals to missing value. if is not 'NA' the convert the _age into numeric? is it??&lt;BR /&gt;&lt;BR /&gt;i'm sorry i very new aboout sas studio. =')&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are completely right about how the step works.&lt;/P&gt;
&lt;P&gt;As for your question: in a dataset, a column can only have one type throughout the dataset, just like you have in database systems. This is where SAS differs from a spreadsheet program like Excel or OpenOffice calc. Since the data step data structures are taken from the contributing datasets, the same is true for the data step: a variable can only be of one type.&lt;/P&gt;
&lt;P&gt;So one has to read mixed type values into a separate character variable and then conditionally convert to numeric values, the character variable can be kept for future reference or be dropped.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could avoid the temporary variable, but trying to read mixed data directly into numeric will cause a lot of messages and finally a WARNING or ERROR in the log. Clean programming avoids those, so when you have them appearing in the log unexpectedly, you know something's wrong in the input data.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 16:16:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Read-from-a-text-file/m-p/309082#M1443</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-03T16:16:11Z</dc:date>
    </item>
  </channel>
</rss>

