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 Kar is an Analyst with over five years of experience. As a programmer specializing in SAS (Statistical Analysis System), Subhro also offers tutorials and guides on how to approach the coding language. His website, 9to5sas, offers students and new programmers useful easy-to-grasp resources to help them understand the fundamentals of SAS. Through this website, he shares his passion for programming while giving back to up-and-coming programmers in the field. Subhro’s mission is to offer quality tips, tricks, and lessons that give SAS beginners the skills they need to succeed.