Published on :
Macro MIXTE

get_append_base Macro for Structure Generation

This code is also available in: Deutsch Español Français
This macro uses PROC CONTENTS to extract metadata from the table specified as a parameter. It then dynamically generates, via a DATA _NULL_ step, SAS© instructions (DATA step with FORMAT instructions) which it writes to the log. This generated code can be copied and pasted to initialize an empty table with the same structure, facilitating append operations (PROC APPEND). It also attempts to clean up the temporary table via a call to an external macro %delete_dataset.
Data Analysis

Type : MIXTE


The macro expects an existing table name as a parameter (&base_dataset). It creates a temporary table 'local_temp' from the metadata.

1 Code Block
MACRO
Explanation :
Definition of the macro that extracts metadata, sorts it by variable order, and writes the SAS format definition code to the log. Note: it calls a utility macro '%delete_dataset' which is not defined in this script.
Copied!
1%macro get_append_base(base_dataset);
2 PROC CONTENTS noprint DATA= &base_dataset. out= local_temp; RUN;
3
4 PROC SORT DATA= local_temp; BY varnum; RUN;
5 
6 DATA _null_;
7 SET local_temp END= last;
8 BY varnum;
9 obs = _N_;
10 ;
11 IF obs = 1 THEN DO;
12 put "***************************************************************************************;";
13 put;
14 put " data stuff;";
15 put " set _null_;";
16 put " format";
17 END;
18 
19 formatted = compress(name) || ' ' || compress(cat(FORMAT,FORMATL,"."));
20 put " " formatted;
21 
22 IF last THEN DO;
23 put " ;";
24 put " run;";
25 put;
26 put "***************************************************************************************;";
27 END;
28 RUN;
29 %delete_dataset(work,local_temp);
30%mend get_append_base;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.