BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi All,

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.

"bank.txt" data:-

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


Kind Regards,
Kriti
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic / post:

proc import site:sas.com

proc import txt file site:sas.com

input external data site:sas.com

data step programming site:sas.com
deleted_user
Not applicable
Hello,

If you want to read your data with a data step a good solution may be the
use of reverse format since your variable, institution, contains embedded blanks (you can
see this posting, it may help: http://support.sas.com/forums/thread.jspa?messageID=47925묵 )
:

data s (drop=rate_int Institution_int);
infile "C:\CWA\bank.txt" ;
input @;
_infile_=reverse(_infile_);
input Years Rate_int $ Institution_int & $30. ;
Rate=input(put(Rate_int, $revers8.),best12.);
Institution=put(Institution_int,$revers25.);
run;

Marius
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

Scott Barry
SBBWorks, Inc.

Additional suggested Google advanced search argument, this topic / post:

data step programming input statement external file site:sas.com
Peter_C
Rhodochrosite | Level 12
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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1577 views
  • 0 likes
  • 3 in conversation