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?
I guess that length statements have to be used here.
MBNA America 0.0817 5
Metro Bank 0.0814 3
Standard Bank 0.0806 4
XYZ 0.0732 5
Australian National Bank 0.043 3
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:
1) PROC IMPORT
2) DATA step programming logic using an INFILE and INPUT statements.
And, with option #1 above, SAS will generate the DATA step for you based on the external input data-field content.
Suggested Google advanced search arguments, this topic / post:
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.
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.
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.
Additional suggested Google advanced search argument, this topic / post:
data step programming input statement external file site:sas.com
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.
A presentation entitled "more _infile_ magic" http://www2.sas.com/proceedings/sugi28/086-28.pdf draws attention to the idea of updating the _infile_ buffer before using input statements.
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.
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 http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000193602.htm after querying the buffer to discover the length of that first data column.
So assuming the physical file name is provided in parameter &Minfile, this solves the problem.[pre]%let minfile = C:\CWA\bank.txt ;
filename minfile "&minfile" lrecl=1000 ;
data got_it( keep= institution Rate Years ) ;
infile Minfile ;
input@ ; * load infile buffer *;
* now get position of second-last column *;
call scan( _infile_, -2, POS, LEN, ' ' ) ;
* that defines the length of this Institution *;
inst_len= pos-1 ;
* so use $varying to read that ill-defined column *;
input institution $varying50. inst_len Rate Years ;
run ;[/pre] of course this solution depends on the Rate and Years data being present.