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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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