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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

View solution in original post

4 REPLIES 4
ballardw
Super User

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.

PGStats
Opal | Level 21

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
ChrisNZ
Tourmaline | Level 20

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_;
  %*read file;
  infile "&file._COPY"  ;
  input;
  put _infile_;
run;

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

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