BookmarkSubscribeRSS Feed
Tiffany
Calcite | Level 5
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
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Tiffany
Calcite | Level 5
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?
data_null__
Jade | Level 19
[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]
Tiffany
Calcite | Level 5
perfect. thank you!

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1830 views
  • 0 likes
  • 3 in conversation