When developing ETL programs with SAS Data Integration (DI) Studio, each transformation you specify has a neath user interface to specify the columns of the datasets(=tables) you create and their type, length and format.
When the existing transformations can not do the job and jou need user written code, you should do as much as possible with the point-and-click interface because
- it enables impact analysis and reverse impact analysis
- your successors will probably not dive into the SAS base code unless they realy need to
- if they ever need to change the columns or their format, they expect changing the specifications in the user interface will do the job
Fortunately SAS discloses the format of the output to the programmer of a user written transformation in macro variables
So I often write my code inside the user written transformation as
%macro format_output(data);
%do _col = 0 %to &&&data._col_count - 1;
length &&&data._col&_col._name &&&data._col&_col._type&&&data._col&_col._length;
%if %length(&&&data._col&_col._format) %then %do;
format &&&data._col&_col._name &&&data._col&_col._format;
%end;
%end;
%mend;
data &_OUTPUT1 (keep=&_OUTPUT1_keep);
%format_output(_OUTPUT1);
set &_INPUT1;
* actua code ;
run;
Does SAS supply an embedded macro or something to do the same thing?
For completenes: the way SAS discloses the structure of the output looks like
%let _OUTPUT1 = myLib.myTable;
%let _OUTPUT1_connect = ;
%let _OUTPUT1_engine = ;
%let _OUTPUT1_memtype = DATA;
%let _OUTPUT1_options = %nrquote();
%let _OUTPUT1_alter = %nrquote();
%let _OUTPUT1_path = %nrquote(/myTable_A5E5JYT6.C7000MOL%(WorkTable%));
%let _OUTPUT1_type = 1;
%let _OUTPUT1_label = %nrquote();
/* List of target columns to keep */
%let _OUTPUT1_keep = myID first_item <16 more items> last_item;
%let _OUTPUT1_col_count = 19;
%let _OUTPUT1_col0_name = myID;
%let _OUTPUT1_col0_table = myLib.myTable;
%let _OUTPUT1_col0_length = 8;
%let _OUTPUT1_col0_type = ;
%let _OUTPUT1_col0_format = 13.;
%let _OUTPUT1_col0_informat = 13.;
%let _OUTPUT1_col0_label = %nrquote(my ID);
%let _OUTPUT1_col0_input0 = myID;
%let _OUTPUT1_col0_exp = ;
%let _OUTPUT1_col0_input = myID;
%let _OUTPUT1_col0_input_count = 1;
%let _OUTPUT1_col1_name = first_item;
%let _OUTPUT1_col1_table = myLib.myTable;
%let _OUTPUT1_col1_length = 8;
%let _OUTPUT1_col1_type = $;
%let _OUTPUT1_col1_format = $CHAR8.;
%let _OUTPUT1_col1_informat = $CHAR8.;
%let _OUTPUT1_col1_label = %nrquote(first data item in my table);
%let _OUTPUT1_col1_input0 = first_item;
%let _OUTPUT1_col1_exp = ;
%let _OUTPUT1_col1_input = first_item;
%let _OUTPUT1_col1_input_count = 1;
<documentation about 16 more columns>
%let _OUTPUT1_col18_name = last_item;
%let _OUTPUT1_col18_table = myLib.myTable;
%let _OUTPUT1_col18_length = 16;
%let _OUTPUT1_col18_type = $;
%let _OUTPUT1_col18_format = $16.;
%let _OUTPUT1_col18_informat = $16.;
%let _OUTPUT1_col18_label = %nrquote(last data item in my table);
%let _OUTPUT1_col18_input0 = last_item;
%let _OUTPUT1_col18_exp = ;
%let _OUTPUT1_col18_input = last_item;
%let _OUTPUT1_col18_input_count = 1;
%let _OUTPUT1_filetype = WorkTable;