BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,
I need to read many text files from a directory into a one SAS data set.
All the text files have the same varibles but different number of observation.
I've tried to use a wildcard into the INFILE and the program works ok:

data pippo;
INFILE "C:\tmp\*.txt"
DLM=';' DSD missover FIRSTOBS=2;
input A
B
C
😧 $4.
E: $9.;
run;

The problem is that i have to read just since the second observation of every text file (becouse the first one are the titles), and if i use the FIRSTOBS option in the INFILE, it applies just for the first text file, but in the other one it reads all the obs.
Do you know how i could apply the FIRSTOBS =2 in every text file?

Thanks,
Elena
6 REPLIES 6
data_null__
Jade | Level 19
When reading with a wild card the files are treated as one stream. There is an option EOV to detect the start of a new file. You could test that variable and use programming logic to skip the first line of the file.

You CAN use FIRSTOBS when reading the files with the FILEVAR option. This requires creating a list of files to be read.

You should consult the documentation regarding the details of these INFILE statement options.
deleted_user
Not applicable
With the help of the option EOV i have got solve the problem

Thank you!
niemannk
Calcite | Level 5
I would be curious to see the result. The way I understand EOV is that it changes from 0 to 1 as soon as it encounters a new file. So reading in more than two files the EOV variable cannot tell you when you start reading in the third file. Or am I wrong?
Peter_C
Rhodochrosite | Level 12
niemannk

you're wrong

EOV is set when "reading after last record" occurs on any file and there is more data to follow, through "*" or file concatenation. So the EOV= flag is set after all files except the last.


PeterC
niemannk
Calcite | Level 5
ok. I played around with it and it looks like i need to reset the eov variable. sort of like this:

if _n_=1 or eov then do;
[...];
eov=0;
end;
data_null__
Jade | Level 19
The documentation is pretty clear on this one.

[pre]
EOV=variable
names a variable that SAS sets to 1 when the first record in a file in a series of
concatenated files is read. The variable is set only after SAS encounters the next
file. Like automatic variables, the EOV= variable is not written to the data set.

Tip: Reset the EOV= variable back to 0 after SAS encounters each boundary.
[/pre]

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
  • 6 replies
  • 12811 views
  • 0 likes
  • 4 in conversation