Help using Base SAS procedures

appending text files

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 440
Accepted Solution

appending text files

Hi,

I have one external text file that i like to append to another but i dont like to read them in into a dataset as the files have many variables. And they both have the same layout. How do i do that?


Accepted Solutions
Solution
‎01-21-2015 10:01 PM
Super User
Posts: 17,784

Re: appending text files

Use your OS commands - in Unix its cat, may be in powershell as well.

Do you have headers you need to deal with or is it straight appending of the two text files.

View solution in original post


All Replies
Solution
‎01-21-2015 10:01 PM
Super User
Posts: 17,784

Re: appending text files

Use your OS commands - in Unix its cat, may be in powershell as well.

Do you have headers you need to deal with or is it straight appending of the two text files.

Super Contributor
Super Contributor
Posts: 440

Re: appending text files

Thx guys. The cat command works perfectly

Super User
Posts: 6,928

Re: appending text files

filename infile ("path_to_file_a","path_to_file_b") options;

if you want to read them in one step.

Otherwise, use the X statement or call system to do it with a suiting OS command, as Reeza suggested.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
SAS Super FREQ
Posts: 682

Re: appending text files

You can make use of the MOD option of the FILE statement, this will allow you to add new records to an existing external file.

see this sample code, that illustrates this:

*
* create base file
*;

filename xbase temp;

data _null_;
 
set sashelp.class;
  where age lt 14;
 
file xbase dsd dlm=",";
 
put name age sex height weight;
run;

*
* create append file
*;

filename xapp temp;

data _null_;
 
set sashelp.class;
  where age ge 14;
 
file xapp dsd dlm=",";
 
put name age sex height weight;
run;

*
* use the base file with the MOD option, so
* that new reords are appended to the file
*;

data _null_;
 
file xbase mod;
 
infile xapp;
  input;
 
put _infile_;
run;

*
* verify the result
*;

data _null_;
 
infile xbase;
  input;
 
putlog _infile_;
run;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1963 views
  • 9 likes
  • 4 in conversation