Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading text file into SAS

Status
Not open for further replies.

wundergal2000

Technical User
Jun 14, 2005
10
US
Hi,

I have a text file in the following format

6387

Ret
-2 1.0048
-1 0.0064
0 -1.3263
1 -1.73829
2 -0.63282

5679

Ret
-2 -2.373
-1 0.3873
0 8.383
1 -7.38
2 0.373

So basically 6387 and 5679 are two different records..and under each record I have 5 different days ranging from 2 days before to two days after with corresponding values of returns.Now i have 80 different records like this one after the other on a text file. How Do I read this in sas and display it correctly? I would be very very very grateful for help on this!
--Nancy
 
Reading in hierarchical text files is a bit of a pain, there are several methods such as using the trailing @ to control your pointer, or multiple input statements. You can also read in each line, test it then decide what to do next (either read in more data for this observation, or output the observation and move on to the next logical record).
Here's the SAS9 documentation which seems to explain it all quite well, it looks like there's nothing new in the data section that can't be used under version 8.

Specifically you want to look at
SAS Online Doc > Base SAS > Step-by-Step Programming with Base SAS Software > Getting Your Data into Shape > Starting with Raw Data: Beyond the Basics
... as this will give you a pretty varied look at the different methods.
This is a direct link.

Enjoy.
 
Oh, and in this sort of situation, I quite often go back to the supplier of the data and find out how easy it is to resupply in a better format, as it might be that it'll take them 5 minutes to resupply the data in a csv format saving you spending half a day trying to code your program to deal with the current format.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top