Append records to an existing file in SAS

The code illustrates how to append records to an existing file in SAS. It can be used to add text to the bottom of an existing file with the MOD option in the FILE statement.

The MOD option on the FILE statement is part of DATA step processing that is particularly used for appending to an existing file.

/* Create a csv file */
data _null_;
	infile datalines trun;
file "/home/9to5sas/examples/file.csv";
input data :$10.;
put data;
datalines;
A
B
C
;
/* Append information to the existing file using MOD option */
data _null_;
file "/home/9to5sas/examples/file.csv" mod;
input data :$10.;
put data;
datalines;
D
E
F
;

Note the use of the PUT statement. PUT statement is used to write output to the SAS log. Here, it is used with the FILE statement to route this output to the same external file.

Every week we'll send you SAS tips and in-depth tutorials

JOIN OUR COMMUNITY OF SAS Programmers!

Subhro

Subhro provides valuable and informative content on SAS, offering a comprehensive understanding of SAS concepts. We have been creating SAS tutorials since 2019, and 9to5sas has become one of the leading free SAS resources available on the internet.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.