Techniques For User Code in SAS Data Integration Studio
Techniques For User Code in SAS Data Integration Studio
Integration Studio
2
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
Example SAS Program: What It Does
SAS
program
source target
data 3 data
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
Moving Measures
4
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
Moving Measures
5
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
Moving Measures
6
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
The Program data movingstatsfor_&source;
set work.sourcesorted;
by &groupvar;
drop i;
array numlist_{&n} _temporary_ ;
if first.&groupvar then do;
%let source=stocks; count=0;
%let n = 6; do i=1 to &n;
%let statvar=high; numlist_{i}=.;
%let groupvar=stock; end;
%let datevar=date; end;
count+1;
do i=&n to 2 by -1;
These macro variables specify numlist_{i}=numlist_{i-1};
- the source data end;
- the number of observations numlist_{1}=&statvar;
(time periods) for each summary if count GE &n then do;
calculation ave_&statvar=sum(of numlist_{*}) / &n;
- the numeric variable on which to min_&statvar=min(of numlist_{*});
calculate moving statistics max_&statvar=max(of numlist_{*});
- the grouping variable range_&statvar=max_&statvar-min_&statvar;
- the time variable. end;
run; 7
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
Scenario
There are two ways to implement this code utility in a Data Integration Studio
job:
1. Use the User Written transformation.
• Source tables can be attached as input. Users still need to modify
the %LET statements as needed. The update metadata utility is
applied by the user to the target table within the job to make the
target table usable by other transformations in the job.
2. Create a new custom transformation.
• This enables users to use the transformation in the same way they
use other SAS Data Integration Studio transformations. Users do
not alter the underlying code and instead use transformation
properties to control how the transformation works.
8
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
User Written Transformation
9
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
User Written Transformation
10
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
User Written Transformation
Here is what you can do with the User Written transformation:
• add your own SAS code to a job flow
• reference one or more source table with &_input(n)
• reference one or more target tables with &_output(n)
• leverage existing code within a job
• add a customization that is not available in the interface
11
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
User Written Transformation
proc sort data = &_input1
out = sortsubjinfo(keep = sdyid subjid usubjid tobacco
alcohol);
by sdyid usubjid;
run;
data &_output1;
set sortsubjinfo;
measure = 'Tobacco';
value = tobacco;
output;
measure = 'Alcohol';
value = alcohol;
output;
drop tobacco alcohol;
run;
12
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
User Written Transformation
%let n = 6;
%let statvar=adjClose;
%let groupvar=stock;
%let datevar=date;
%let source=&_input1;
data &_output1;
set work.sourcesorted;
by &groupvar;
format _numeric_ ;
format &datevar date9.;
drop i;
array numlist_{&n} _temporary_ ;
if first.&groupvar then do;
count=0;
do i=1 to &n;
…
…
run;
13
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
Update Metadata
The easiest method to define the column metadata for the target table for
user-written code or custom transformations is often the following:
1. Execute the transformation to create the physical target table.
2. Use Update Metadata for the physical target table.
With Update Metadata, the structure of the physical table is read by SAS and
is used to define the table metadata within the SAS Data Integration Studio
job. 14
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
User-Defined Transformations
The New Transformation Wizard can be used to convert user-written SAS
code into custom transformations that work like any other transformation.
• drag and drop from the Transformation tab.
• connect desired source tables and target tables.
• assign source or target columns (or both) to roles in transformation
properties.
• specify other properties as required. User choices for these properties are
assigned to macro variable values used in the code.
15
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
Implementing a SAS Program in
a SAS Data Integration Studio Job
The best use is for one-time The best use is for general
application of code in a specific job application of code utility for
for a specific data source. various data sources in multiple
jobs.
18
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.