How to validate that a file exist without mistakes? Note the filexist function not say about a wrong file.
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
What is your definition of a file that is wrong or exists without mistakes?
@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.
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.
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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.