<?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: Using Input in SAS in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Using-Input-in-SAS/m-p/65293#M18625</link>
    <description>awkward for a data step, but not impossible because the challenge - an unquoted column which might hold an embedded delimiter - occurs in one fixed (data) column - in this case it is the first column.&lt;BR /&gt;
A presentation entitled "more _infile_ magic" &lt;A href="http://www2.sas.com/proceedings/sugi28/086-28.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi28/086-28.pdf&lt;/A&gt; draws attention to the idea of updating the _infile_ buffer before using input statements. &lt;BR /&gt;
Here we might want to quote the first data column. We can define the end of that by the beginning of the second last column. Although the SCAN(_infile_,-2) function does provide the text of the second last column, more help comes from the CALL routine:[pre]call  scan( _infile_, -2, POS, LEN ) ; [/pre]provides the all important POS =position of the RATE column. &lt;BR /&gt;
However, rather than shift the _infile_ buffer and insert quotes, we can use another piece of the amazingly diverse parsing of the INPUT statement, - $varying informat &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000193602.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000193602.htm&lt;/A&gt; after querying the buffer to discover the length of that first data column.&lt;BR /&gt;
 &lt;BR /&gt;
So assuming the physical file name is provided in parameter &amp;amp;Minfile, this solves the problem.[pre]%let minfile = C:\CWA\bank.txt ;&lt;BR /&gt;
&lt;BR /&gt;
filename minfile "&amp;amp;minfile" lrecl=1000 ;&lt;BR /&gt;
&lt;BR /&gt;
data got_it( keep= institution  Rate  Years )  ;&lt;BR /&gt;
  infile Minfile  ;&lt;BR /&gt;
  input@ ; * load infile buffer                              *;&lt;BR /&gt;
           * now get position of second-last column          *; &lt;BR /&gt;
  call  scan( _infile_, -2, POS, LEN, ' ' ) ; &lt;BR /&gt;
           * that defines the length of this Institution     *;&lt;BR /&gt;
  inst_len= pos-1 ;&lt;BR /&gt;
           * so use $varying to read that ill-defined column *;&lt;BR /&gt;
  input institution $varying50. inst_len  Rate  Years ;&lt;BR /&gt;
run ;[/pre] of course this solution depends on the Rate and Years data being present.</description>
    <pubDate>Mon, 24 Jan 2011 13:03:37 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2011-01-24T13:03:37Z</dc:date>
    <item>
      <title>Using Input in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Input-in-SAS/m-p/65289#M18621</link>
      <description>Hi All,&lt;BR /&gt;
&lt;BR /&gt;
I have the following data and the variables are: Institution, Rate and Years. How do I run the data. Is there a way that I can run the data with just knowledge of the location of the file say at - "C:\CWA\bank.txt"; and retrieve the data in improper form?&lt;BR /&gt;
&lt;BR /&gt;
I guess that length statements have to be used here.&lt;BR /&gt;
&lt;BR /&gt;
"bank.txt" data:-&lt;BR /&gt;
&lt;BR /&gt;
MBNA America 0.0817 5&lt;BR /&gt;
Metro Bank 0.0814 3&lt;BR /&gt;
Standard Bank 0.0806 4    &lt;BR /&gt;
XYZ 0.0732 5&lt;BR /&gt;
Australian National Bank 0.043 3&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Kind Regards,&lt;BR /&gt;
Kriti</description>
      <pubDate>Sun, 23 Jan 2011 13:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Input-in-SAS/m-p/65289#M18621</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-23T13:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using Input in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Input-in-SAS/m-p/65290#M18622</link>
      <description>If I understand correctly, you want to "input the data" from an external file (you list) using SAS.   You have a few options, depending on what control you want to have, as follows for your review/decision:&lt;BR /&gt;
&lt;BR /&gt;
1) PROC IMPORT&lt;BR /&gt;
2) DATA step programming logic using an INFILE and INPUT statements.&lt;BR /&gt;
&lt;BR /&gt;
And, with option #1 above, SAS will generate the DATA step for you based on the external input data-field content.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search arguments, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
proc import site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
proc import txt file site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
input external data site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
data step programming site:sas.com</description>
      <pubDate>Sun, 23 Jan 2011 14:24:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Input-in-SAS/m-p/65290#M18622</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-01-23T14:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using Input in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Input-in-SAS/m-p/65291#M18623</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
If you want to read your data with a data step a good solution may be the&lt;BR /&gt;
use of reverse format since your variable, institution, contains embedded blanks (you can &lt;BR /&gt;
see this posting, it may help: &lt;A href="http://support.sas.com/forums/thread.jspa?messageID=47925묵" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=47925묵&lt;/A&gt; )&lt;BR /&gt;
:&lt;BR /&gt;
&lt;BR /&gt;
data s (drop=rate_int Institution_int);&lt;BR /&gt;
infile "C:\CWA\bank.txt" ;&lt;BR /&gt;
input @;&lt;BR /&gt;
_infile_=reverse(_infile_);&lt;BR /&gt;
input Years Rate_int $ Institution_int &amp;amp; $30.    ;&lt;BR /&gt;
Rate=input(put(Rate_int, $revers8.),best12.);&lt;BR /&gt;
Institution=put(Institution_int,$revers25.);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Marius</description>
      <pubDate>Sun, 23 Jan 2011 19:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Input-in-SAS/m-p/65291#M18623</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-23T19:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using Input in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Input-in-SAS/m-p/65292#M18624</link>
      <description>Marius makes a very observant point that I overlooked.  The OP has input data with a "blank delimiter", however the first data-field also "appears" to have embedded blanks, creating an "input logic" challenge.  Given the prior post from Marius, I would submit that PROC IMPORT will not work.  &lt;BR /&gt;
&lt;BR /&gt;
Also, with an HTML-formatted post for the OP, it's really impossible to interpret just how the external data file is formatted, either with "two or more blanks" separating each field, or a non-printable delimiter character, or ideally a fixed-format (column-controlled) data-file layout.&lt;BR /&gt;
&lt;BR /&gt;
To the question posed, if the input data is a fixed-format layout, where input fields occupy specific a column (or column range), the INPUT statement and the INFORMAT specification will be sufficient, such as $CHAR15. yields a SAS CHARACTER variable, length 15.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Additional suggested Google advanced search argument, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
data step programming input statement external file site:sas.com</description>
      <pubDate>Sun, 23 Jan 2011 20:12:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Input-in-SAS/m-p/65292#M18624</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-01-23T20:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: Using Input in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Input-in-SAS/m-p/65293#M18625</link>
      <description>awkward for a data step, but not impossible because the challenge - an unquoted column which might hold an embedded delimiter - occurs in one fixed (data) column - in this case it is the first column.&lt;BR /&gt;
A presentation entitled "more _infile_ magic" &lt;A href="http://www2.sas.com/proceedings/sugi28/086-28.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi28/086-28.pdf&lt;/A&gt; draws attention to the idea of updating the _infile_ buffer before using input statements. &lt;BR /&gt;
Here we might want to quote the first data column. We can define the end of that by the beginning of the second last column. Although the SCAN(_infile_,-2) function does provide the text of the second last column, more help comes from the CALL routine:[pre]call  scan( _infile_, -2, POS, LEN ) ; [/pre]provides the all important POS =position of the RATE column. &lt;BR /&gt;
However, rather than shift the _infile_ buffer and insert quotes, we can use another piece of the amazingly diverse parsing of the INPUT statement, - $varying informat &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000193602.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000193602.htm&lt;/A&gt; after querying the buffer to discover the length of that first data column.&lt;BR /&gt;
 &lt;BR /&gt;
So assuming the physical file name is provided in parameter &amp;amp;Minfile, this solves the problem.[pre]%let minfile = C:\CWA\bank.txt ;&lt;BR /&gt;
&lt;BR /&gt;
filename minfile "&amp;amp;minfile" lrecl=1000 ;&lt;BR /&gt;
&lt;BR /&gt;
data got_it( keep= institution  Rate  Years )  ;&lt;BR /&gt;
  infile Minfile  ;&lt;BR /&gt;
  input@ ; * load infile buffer                              *;&lt;BR /&gt;
           * now get position of second-last column          *; &lt;BR /&gt;
  call  scan( _infile_, -2, POS, LEN, ' ' ) ; &lt;BR /&gt;
           * that defines the length of this Institution     *;&lt;BR /&gt;
  inst_len= pos-1 ;&lt;BR /&gt;
           * so use $varying to read that ill-defined column *;&lt;BR /&gt;
  input institution $varying50. inst_len  Rate  Years ;&lt;BR /&gt;
run ;[/pre] of course this solution depends on the Rate and Years data being present.</description>
      <pubDate>Mon, 24 Jan 2011 13:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Input-in-SAS/m-p/65293#M18625</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-01-24T13:03:37Z</dc:date>
    </item>
  </channel>
</rss>

