0% found this document useful (0 votes)
68 views18 pages

Techniques For User Code in SAS Data Integration Studio

Uploaded by

Cristiano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views18 pages

Techniques For User Code in SAS Data Integration Studio

Uploaded by

Cristiano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Techniques for User Code in SAS® Data

Integration Studio

Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.


Scenario
• A SAS program is developed to derive moving averages and other moving
measures for transactional data.
• The program is generalized with macro variables as a general purpose utility.
• I will show 2 ways to implement this custom program as a step in a SAS Data
Integration Studio job:
- via a User Written transformation
- via a user-defined custom transformation designed with the New Transformation wizard

This will serve as an example to demonstate how to implement any custom


SAS code in SAS Data Integration Studio jobs.

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

You can connect source tables to


the User Written transformation.

Temporary or permanent target


tables can be created and
connected to subsequent
transformations.

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;

proc sort data=&source out=work.sourcesorted;


by &groupvar &datevar;
run;

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

Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.


Key Steps
User Written Transformation Custom Transformation
1. Specify macro variables for input/output data 1. Specify macro variables for the input/output
sets. data sets and for all other code elements that
2. In a job, add the SAS program to the User will be modifiable by transformation users via
Written transformation. parameters.
3. Connect the source and target tables to the 2. Add SAS program to the custom transformation.
User Written transformation. 3. Define the parameters that will be available for
4. Run the transformation. users as transformation options.
5. Update the target table to match the physical 4. In a job, add the custom transformation.
table created by the User Written code. 5. Connect the desired course and target tables to
the custom transformation.
6. Define parameters as desired.
7. Run the transformation.
8. Update the target table to match the physical
17 table created by the custom transformation.
Copy rig ht © SA S Institute Inc. A ll rig hts re se rve d.
User Written Code versus Custom Transformation

User Written Custom


Job designer must add code to the Job designer adds a
transformation. transformation with existing code
embedded in the transformation
Input and output data sets can be Any options can be added via the
added through the visual interface. pre-built parameter interface.

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.

You might also like