BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
riarangogi
Fluorite | Level 6

How to validate that a file exist without mistakes? Note the filexist function not say about a wrong file.

1 ACCEPTED SOLUTION

Accepted Solutions
FredrikE
Rhodochrosite | Level 12

One thing we use a lot is a file header (the first line in the file) and a file footer (the last line in the file).

In the header number of rows are specified, also file creation date and name.

 

By reading the header we get information about the file which we then use to make an initial check if it's ok.

If so we stop.

 

If ok, we read the file and if we reach the footer we check the number of rows again.

 

//Fredrik

View solution in original post

6 REPLIES 6
SASKiwi
PROC Star

What is your definition of a file that is wrong or exists without mistakes?

riarangogi
Fluorite | Level 6
Is when I can import a file.So, I want know how to detect the files we could import.
Reeza
Super User

@riarangogi wrote:
Is when I can import a file.So, I want know how to detect the files we could import.


It depends, if you don’t have PCFILES you can’t open an XLSX file. Your criteria is still too broad. 

Vague question = vague answer. 

 

 

 

riarangogi
Fluorite | Level 6

What happens if the file exists but is damaged?

 

If file.txt is a  wrong file, then filexist function is true but I can't import it.

Kurt_Bremser
Super User

How would you detect that a .txt file is "wrong"? Once you know that, you can create code out of this algorithm. Note that you will have to read the file, and determine its state by the contents you read.

FredrikE
Rhodochrosite | Level 12

One thing we use a lot is a file header (the first line in the file) and a file footer (the last line in the file).

In the header number of rows are specified, also file creation date and name.

 

By reading the header we get information about the file which we then use to make an initial check if it's ok.

If so we stop.

 

If ok, we read the file and if we reach the footer we check the number of rows again.

 

//Fredrik

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1169 views
  • 4 likes
  • 5 in conversation