Adding data to a SAS dataset

This short article describes how to add two files with data to a SAS dataset. Assume both files use the same format for the data.

The first approach uses a more or less standard technique wereby a global variable (fileref) is created that refers to two files.

filename gegs ('C:\Users\tomva\SynologyDrive\SAS\gegs.txt' 'C:\Users\tomva\SynologyDrive\SAS\gegs2.txt');
data ff;
infile gegs;
input nummer 1-3 naam $;
run;

The second approach creates a place holder that is linked to a file variable that is loaded with different file names. Each file is read sequentially. While the SAS read procedure loops through the records, each record is written to the target SAS dataset with the output statement.

data score45;
infile datalines;
length rfile $60;
input rfile $;
infile PH filevar=rfile end=lastobs;
do until (lastobs);
input nummer naam $;
output;
end;
datalines;
C:\Users\tomva\SynologyDrive\SAS\gegs.txt
C:\Users\tomva\SynologyDrive\SAS\gegs2.txt
;
run;

Door tom