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 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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1528 views
  • 4 likes
  • 5 in conversation