## Import a CSV file that could be opened by someone else

Solved
Frequent Contributor
Posts: 127

# Import a CSV file that could be opened by someone else

Hi all,

My question is quite simple, is it possible to avoid getting an error when running a proc import of a CSV file that would be opened by someone else during the execution of the SAS program ?

I am using SAS 9.4 (M1) 32bits on Microsoft 7.

Thanks in advance for the feedback!

Kr,

Florent

Accepted Solutions
Solution
‎04-14-2016 04:57 PM
Posts: 4,651

## Re: Import a CSV file that could be opened by someone else

If you make the file readonly (in Windows) then you can concurently read in in, say, Excel and import it with SAS. Another option is to open the file for readonly in Excel (it's an option in the open dialog); you can then import it with SAS at the same time.

PG

All Replies
Super User
Posts: 10,516

## Re: Import a CSV file that could be opened by someone else

It depends on the program the other person is using to view the file. Some applications lock the file for possible editing, Excel, Word, Wordpad and such are examples. If the file is viewed with something that doesn't locke the file such as a web browser then the file isn't locked and can be read by multile users.

Since this is more of an operating system behavior I'm not sure much can be done is SAS other than to try to copy the file before someone else opens and locks it.

Solution
‎04-14-2016 04:57 PM
Posts: 4,651

## Re: Import a CSV file that could be opened by someone else

If you make the file readonly (in Windows) then you can concurently read in in, say, Excel and import it with SAS. Another option is to open the file for readonly in Excel (it's an option in the open dialog); you can then import it with SAS at the same time.

PG
PROC Star
Posts: 1,563

## Re: Import a CSV file that could be opened by someone else

Even if the file is open ni Excel, Windows can copy it.

You could do something like this:


%let file    =path\text.csv;

data _null_;
%*copy file and display OS process output;
infile  "copy ""&file"" ""&file._COPY"" " pipe;
input;
put _infile_;
run;

data _null_;
infile "&file._COPY"  ;
input;
put _infile_;
run;

%*delete file when done;
x "del ""&file._COPY"" " ;


Super User
Posts: 7,407

## Re: Import a CSV file that could be opened by someone else

Why would you encounter this issue?  The import procedure should be a documented process whereby data is recieved and imported, then validated, at no point in the process should the file be open by someone else?  What if they change somethin and save after your program has finished for example.  Identify the part of the process that is failing and fix that rather than trying to work around it.

☑ This topic is SOLVED.