BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Here's my program:

data _NULL_;
length testFile $20;

testFile = "testFile0.txt";
file out filevar=testFile notitle noprint;
put "THIS IS A TEST";

testFile = "testFile1.txt";
file out filevar=testFile notitle noprint;
put "This is a test";

testFile = "testFile0.txt";
file out filevar=testFile MOD notitle noprint;
put "THIS IS A TEST";

testFile = "testFile1.txt";
file out filevar=testFile MOD notitle noprint;
put "This is a test";

testFile = "testFile0.txt";
file out filevar=testFile notitle noprint;
put "THIS IS A TEST";

testFile = "testFile1.txt";
file out filevar=testFile notitle noprint;
put "This is a test";
run;

Here is the new file: testFile0.txt:

THIS IS A TEST
THIS IS A TEST
THIS IS A TEST

Here is testFile0.txt again, after a second run of the same SAS program, when I haven't deleted testFile0.txt from the previous run, and I have completely restarted the SAS program:

THIS IS A TEST
THIS IS A TEST
THIS IS A TEST
THIS IS A TEST
THIS IS A TEST
THIS IS A TEST

I would prefer that testFile0.txt be rebuilt from scratch, not Modded every time (otherwise the first FILE statement would have contained a MOD, as would the third).

The MOST preferable output of this program would be for testFile0.txt to look like:

THIS IS A TEST

since I didn't declare MOD on the third statement. Anyone know how I can get SAS to follow this functionality since it seems to be assuming MOD on every file statement? I tried OLD on the non-MOD statements, but that seemed to have no affect whatsoever on the output.

Thanks much!
-Jim
2 REPLIES 2
data_null__
Jade | Level 19
You can achieve the desired result using another name as the fileref. The FILE statement has parts that are compiled and other parts that are executable DISPOSITION is compiled so when MOD is specified it applies to all file statements with the same name OUT. You will need to release the last file referenced with OUTOLD as shown below.

[pre]
data _NULL_;
length testFile $20;

testFile = "testFile0.txt";
file outold filevar=testFile notitle noprint;
put "THIS IS A TEST 1";

testFile = "testFile1.txt";
file outold filevar=testFile notitle noprint;
put "This is a test 1";

testfile = 'dummy';
file outold filevar=testfile;

testFile = "testFile0.txt";
file out filevar=testFile MOD notitle noprint;
put "THIS IS A TEST 2";


testFile = "testFile1.txt";
file out filevar=testFile MOD notitle noprint;
put "This is a test 2";

testFile = "testFile0.txt";
file out filevar=testFile notitle noprint;
put "THIS IS A TEST 3";

testFile = "testFile1.txt";
file out filevar=testFile notitle noprint;
put "This is a test 3";
run;
[/pre] Message was edited by: data _null_;
deleted_user
Not applicable
Hey data _null_;,
That worked perfectly! Thank you for the great advice. It was exactly what I needed to know 😄
-Jim

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1202 views
  • 0 likes
  • 2 in conversation