Macros for SAS Application Developers
https://github.com/sasjs/core
mp_appendfile.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Append (concatenate) two or more files.
4  @details Will append one more more `appendrefs` (filerefs) to a `baseref`.
5  Uses a binary mechanism, so will work with any file type. For that reason -
6  use with care! And supply your own trailing carriage returns in each file..
7 
8  Usage:
9 
10  filename tmp1 temp;
11  filename tmp2 temp;
12  filename tmp3 temp;
13  data _null_; file tmp1; put 'base file';
14  data _null_; file tmp2; put 'append1';
15  data _null_; file tmp3; put 'append2';
16  run;
17  %mp_appendfile(baseref=tmp1, appendrefs=tmp2 tmp3)
18 
19 
20  @param [in] baseref= (0) Fileref of the base file (should exist)
21  @param [in] appendrefs= (0) One or more filerefs to be appended to the base
22  fileref. Space separated.
23 
24  @version 9.2
25  @author Allan Bowe, source: https://github.com/sasjs/core
26 
27  <h4> SAS Macros </h4>
28  @li mp_abort.sas
29  @li mp_binarycopy.sas
30 
31 
32 **/
33 
34 %macro mp_appendfile(
35  baseref=0,
36  appendrefs=0
37 )/*/STORE SOURCE*/;
38 
39 %mp_abort(iftrue= (&baseref=0)
40  ,mac=&sysmacroname
41  ,msg=%str(Baseref NOT specified!)
42 )
43 %mp_abort(iftrue= (&appendrefs=0)
44  ,mac=&sysmacroname
45  ,msg=%str(Appendrefs NOT specified!)
46 )
47 
48 %local i;
49 %do i=1 %to %sysfunc(countw(&appendrefs));
50  %mp_abort(iftrue= (&syscc>0)
51  ,mac=&sysmacroname
52  ,msg=%str(syscc=&syscc)
53  )
54  %mp_binarycopy(inref=%scan(&appendrefs,&i), outref=&baseref, mode=APPEND)
55 %end;
56 
57 %mend mp_appendfile;