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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Multiple Lines of Raw Data

Status
Not open for further replies.

JulianGER

Technical User
Apr 23, 2009
6
DE
Hello all together,

i am pretty new to SAS and have a small question.

I want do import a File which is available either in csv, txt or excel. The Variables are Date ID Price. I have several observations per line. and want I want to create a SAS file with only 3 variable. Can somebody help me? Thank you in advance.

The source looks like this:
Code:
02.02.06	1	9.051	02.02.06	2	0.890	02.02.06	3	4.303	02.02.06	4	29.900	02.02.06	5	1.990
03.02.06	1	8.934	03.02.06	2	0.890	03.02.06	3	4.303	03.02.06	4	29.310	03.02.06	5	2.050
06.02.06	1	8.673	06.02.06	2	0.870	06.02.06	3	4.373	06.02.06	4	29.350	06.02.06	5	2.150
07.02.06	1	8.973	07.02.06	2	0.870	07.02.06	3	4.224	07.02.06	4	29.330	07.02.06	5	2.220
08.02.06	1	8.770	08.02.06	2	0.870	08.02.06	3	4.224	08.02.06	4	29.350	08.02.06	5	2.430
09.02.06	1	8.867	09.02.06	2	0.860	09.02.06	3	4.313	09.02.06	4	29.350	09.02.06	5	2.450
10.02.06	1	8.857	10.02.06	2	0.850	10.02.06	3	4.323	10.02.06	4	29.650	10.02.06	5	2.400
13.02.06	1	8.770	13.02.06	2	0.860	13.02.06	3	4.373	13.02.06	4	30.000	13.02.06	5	2.350
14.02.06	1	8.731	14.02.06	2	0.860	14.02.06	3	4.353	14.02.06	4	30.000	14.02.06	5	2.290
15.02.06	1	8.556	15.02.06	2	0.850	15.02.06	3	4.442	15.02.06	4	30.000	15.02.06	5	2.270
16.02.06	1	8.682	16.02.06	2	0.860	16.02.06	3	4.423	16.02.06	4	30.100	16.02.06	5	2.260
17.02.06	1	8.585	17.02.06	2	0.860	17.02.06	3	4.403	17.02.06	4	30.000	17.02.06	5	2.250
20.02.06	1	8.585	20.02.06	2	0.870	20.02.06	3	4.373	20.02.06	4	29.810	20.02.06	5	2.430
21.02.06	1	8.682	21.02.06	2	0.870	21.02.06	3	4.403	21.02.06	4	30.000	21.02.06	5	2.250
22.02.06	1	8.983	22.02.06	2	0.860	22.02.06	3	4.323	22.02.06	4	30.000	22.02.06	5	2.250
23.02.06	1	8.828	23.02.06	2	0.870	23.02.06	3	4.472	23.02.06	4	30.600	23.02.06	5	2.340
24.02.06	1	8.731	24.02.06	2	0.870	24.02.06	3	4.512	24.02.06	4	31.000	24.02.06	5	2.360
27.02.06	1	8.488	27.02.06	2	0.860	27.02.06	3	4.423	27.02.06	4	31.200	27.02.06	5	2.260
28.02.06	1	8.624	28.02.06	2	0.930	28.02.06	3	4.323	28.02.06	4	31.200	28.02.06	5	2.220
01.03.06	1	8.517	01.03.06	2	0.940	01.03.06	3	4.423	01.03.06	4	30.800	01.03.06	5	2.340
02.03.06	1	8.382	02.03.06	2	0.900	02.03.06	3	4.403	02.03.06	4	30.600	02.03.06	5	2.330

Can somebody tell me how to import this in
 
Do you know up front how many observations are on each record? If so, you could use a do loop, and use the "trailing @" on your input statement. The trailing @ tells SAS to not go to the next record yet, so you can have a second input statement and read from the same line. When you go to the next datastep iteration though, SAS will move the pointer to the next record (a trailing @@ will retain the pointer position between iterations).

So, you'd have something like this (sorry, this'll be rough untested code, it's early and I have a headache, so no guarantees it works, but it should be pretty close to what you need :)
I'm assuming that you have 5 observations per record. If you don't know at the time of coding how many observations there are on each record, you can keep looping until the data you read in is empty, then escape the loop.
Code:
data test;
  infile blah recfm=v lrecl=2056 dsd dlm='09'x missover;

  length Date  8
         ID    4
         Price 8
         ;
  retain recno 0;
  recno + 1;

  do i = 1 to 5;
    input date
          ID
          price  @;
    output;
  end;
run;
I added in the recno field as a counter so that when you look at the data later you'll be able to see what original record each observation came from.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Thanks Chris.
Currentlz I am in holidaz. I^ll trz this code on Tuesdas. Thank you very much for the quick answer. Highly appreciated.

Julian
 
Thx a lot, worked perfect. The only problem I had was that I needed to format dates in Excel as number and than subtract 21916 to form it into a SAS Date.

Thank Youu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top