Perform the following steps to add user-written code to the User Written Code transformation
in a job:
-
Write SAS code and test it to ensure that it produces the required output. The following
code was written for the sample job:
data
&_OUTPUT;
set &SYSLAST;
length sex $1;
if gender = "Male" then
sex = "M";
else if gender = "Female" then
sex = "F";
else
sex="U";
run;
In this case, the code changes the gender identification
in the Gender column from the words Male and Female to the initials
M and F.
-
Open the
Code tab
in the properties window for the User Written Code transformation
on the
Diagram tab of the
Job
Editor window. Code is generated for the transformation
and displayed on the
Code tab. The
Code
generation mode field defaults to
User written
body.
-
Select the code generation
mode. The
Code generation mode field defaults
to
User written body. Note that any non-user-written
portion of the code is dimmed when you select
User written
body. You cannot modify this part of the code.
-
-
-
Click
Save or
Save
As on the toolbar for the tab. The
Save option enables you to save the code in the editor as a
metadata object (instead of saving the code into a file). The
Save As option
opens the
Save File window, where you can
either save a name and description for the metadata object (code in
the editor) or save the contents of the editor as a file.
Note: The
Save and
Save
As options apply your changes to the current session.
To make your changes persist after the current session, you must save
the entire job. To save the entire job, select
FileSave from
the menu bar on the desktop.
-
Click
OK to
save the changes and close the properties window.
-
Make sure that the User
Written Code transformation is selected on the
Diagram tab
of the
Job Editor window. Then, click the
Mappings tab
in the Details section.
-
Create column mappings between the source table and the target table.
Note: When SAS Data Integration
Studio generates all of the code for a job, it can automatically generate
the metadata for column mappings between sources and targets. However,
when you specify user-written code for part of a job, you must manually
define the column metadata for that part of the job that the user-written
code handles. SAS Data Integration Studio needs this metadata to generate
the code for the part of the job that comes after the User Written
Code transformation. This mapping is also needed for impact analysis.
At this point, you have updated the User Written Code transformation so that it can
retrieve the appropriate code when the job is executed.
Note: If a job contains a User
Written Code transformation, and the source or target is an external
file, then the generated code contains additional macro variables
to access that file. Those macros include the following:
-
%LET _INPUT (for source) or _OUTPUT (for target): contains the full path to the file
location of the external file
-
%LET for _INPUTn and _OUTPUTn (where n represents the nth source or target): contains
the path to the file location of the external file
Regardless of the source or target type, code is generated
for macro variables _INPUT_filetype and _OUTPUT_filetype with a value
of either PhysicalTable or ExternalFile. Other generated macro variables
include _INPUTn_filetyper, _OUTPUTn_filetype, _INPUTn, and _OUTPUTn.