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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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