- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 04-08-2010 10:22 AM
(2091 views)
Hello,
I am trying to pull data from a .dat file based on pattern matching criteria. This file has extra info about locations, conditions, instruments, etc. at the start of the file, but the data I want is further down. I am able to using matching criteria to obtain the first line of data, but then it stops after that line because the match no longer applies.
Ex:
** Today's data file
Location = river brook
Three staff present
Lamprey tracking project
Date Time Location Sample Total
03/08/10 08:10 001 034 56
03/08/10 08:15 001 035 56
data counts;
infile 'C:\mydata\file.dat';
input @'Location Sample Total ' date time $8. location sample total;
run;
Is there a way to match to read the first line and then continue reading until the end? Or some other way to pull only certain info form this file? Thank you for any suggestions! Message was edited by: Tiffany
I am trying to pull data from a .dat file based on pattern matching criteria. This file has extra info about locations, conditions, instruments, etc. at the start of the file, but the data I want is further down. I am able to using matching criteria to obtain the first line of data, but then it stops after that line because the match no longer applies.
Ex:
** Today's data file
Location = river brook
Three staff present
Lamprey tracking project
Date Time Location Sample Total
03/08/10 08:10 001 034 56
03/08/10 08:15 001 035 56
data counts;
infile 'C:\mydata\file.dat';
input @'Location Sample Total ' date time $8. location sample total;
run;
Is there a way to match to read the first line and then continue reading until the end? Or some other way to pull only certain info form this file? Thank you for any suggestions! Message was edited by: Tiffany
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
From the data-sample you provided, there will be no match - where is the string "Events " in your input?
Get your INPUT stmt @'' sorted out and then use the END=EOF parameter on the INFILE statement, and code a DO / END loop logic after you get the record pointer to the start of your data. You will likely have at least two INPUT statements, one outside the DO loop (ahead to get to the desired input location) and another (one or more as needed) to perform the data record INPUT processing.
For self-checking, suggest adding one or more PUTLOG commands in your code at various points (use "nnn" to identify each uniquely):
PUTLOG '>DIAG-nnn>' / _all_;
..and/or...
PUTLOG '>DIAG-nnn>' / _infile_;
Scott Barry
SBBWorks, Inc.
Get your INPUT stmt @'
For self-checking, suggest adding one or more PUTLOG commands in your code at various points (use "nnn" to identify each uniquely):
PUTLOG '>DIAG-nnn>' / _all_;
..and/or...
PUTLOG '>DIAG-nnn>' / _infile_;
Scott Barry
SBBWorks, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Scott!
This is what I have now, but I am still missing something critical:
data counts;
infile 'C:\mydata\file.dat' end=eof;
input @'Location Sample Total ' date time $8. location sample total;
do until (eof);
input date time $8. location sample total;
end;
run;
any thoughts?
This is what I have now, but I am still missing something critical:
data counts;
infile 'C:\mydata\file.dat' end=eof;
input @'Location Sample Total ' date time $8. location sample total;
do until (eof);
input date time $8. location sample total;
end;
run;
any thoughts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
[pre]
data counts;
infile 'C:\mydata\file.dat' end=eof;
input @'Location Sample Total ' date time $8. location sample total;
do until (eof);
input date time $8. location sample total;
output;
end;
stop;
run;
[/pre]
data counts;
infile 'C:\mydata\file.dat' end=eof;
input @'Location Sample Total ' date time $8. location sample total;
do until (eof);
input date time $8. location sample total;
output;
end;
stop;
run;
[/pre]
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
perfect. thank you!