Help using Base SAS procedures

My Program seems to run MOD on File Statements when MOD is not declared.

Reply
N/A
Posts: 0

My Program seems to run MOD on File Statements when MOD is not declared.

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
Respected Advisor
Posts: 3,777

Re: My Program seems to run MOD on File Statements when MOD is not declared.

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_;
N/A
Posts: 0

Re: My Program seems to run MOD on File Statements when MOD is not declared.

Hey data _null_;,
That worked perfectly! Thank you for the great advice. It was exactly what I needed to know Smiley Very Happy
-Jim
Ask a Question
Discussion stats
  • 2 replies
  • 101 views
  • 0 likes
  • 2 in conversation