I have a process in SAS that creates a .csv. I have another process in Python that waits until the file exists and then does something with that file. I want to make sure that the Python process doesn't start doing its thing until SAS is done writing the file.

I thought I would just have SAS create the .csv and then rename the file after it was done. Can I do the renaming in SAS? Then the python process could just wait until the renamed file existed.

asked 14 Nov '10, 21:00

rstlne's gravatar image

accept rate: 0%

edited 15 Nov '10, 01:24

sasfrog's gravatar image


You could make use of the X command after the SAS step that creates the .csv file. The X command gives you access to your operating system, effectively placing you in a cmd window in XP. It's likely you'll want to use options noxwait; which will return control to your SAS session after executing the operating environment command.

Something like:

options noxwait;

data _null_;
  file "C:\myFolder\dummyName.csv";
  * ...code that creates the .csv with dummy name... ;

x 'ren C:\myFolder\dummyName.csv realName.csv';

Note that

  • depending on how you're executing SAS, the x command may not be enabled (for example if you're in EG, it's disabled be default), and
  • the execution context is the OS of the server running SAS, not your client, so if you're running SAS on a remote server, the file locations and references must be relative to the SAS server, not your local machine.

answered 15 Nov '10, 01:22

sasfrog's gravatar image

accept rate: 57%

this is working for me. i have some space in my directory names, so that took me awhile to figure out, but now i'm up and running. (I used the %str function)

(15 Nov '10, 02:02) rstlne

Edit: This suggestion is for version 9.2 and later (thanks @sasfrog for the heads up!).

SAS has a built in rename function that you can use. This bypasses the issues that you might run into with restrictions on the 'x' command and is portable to different hosts.


data _null_;
  file "C:\temp\first.csv";
  put "1, 2, 3";

data _null_;
  rc=rename('C:\temp\first.csv', 'C:\temp\second.csv','file');

answered 15 Nov '10, 20:11

cmjohns's gravatar image

accept rate: 50%

edited 16 Nov '10, 15:24


+1 I didn't know about this function - note that it is new for 9.2. I assumed the OP is using SAS 9.1.3, given he's on XP, but I could be wrong.

(15 Nov '10, 23:21) sasfrog

@sasfrog You are correct - this is 9.2 and later - I added an edit to clarify this point.

(16 Nov '10, 15:25) cmjohns

thanks to both of you. we actually have 9.2 on some of our xp machines and 9.1.x on some others, so i probably will not use rename for now. looks like a better solution though for down the road.

(18 Nov '10, 05:16) rstlne
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 14 Nov '10, 21:00

Seen: 5,019 times

Last updated: 16 Nov '10, 15:24

powered by OSQA