Published on :
ETL CREATION_INTERNE

Direct data reading with index (KEY=)

This code is also available in: Deutsch Español Français
Awaiting validation
This program illustrates the 'Direct Access' or index-based reading technique in a SAS© DATA step. It creates two temporary datasets (x and y), one of which is indexed. The third step performs a join where, for each row of x, SAS© attempts to directly retrieve the corresponding row in y via the index, displaying the return code _IORC_ for diagnostic purposes.
Data Analysis

Type : CREATION_INTERNE


All data (tables x and y) are dynamically generated in the script using loops and random functions (uniform, ranuni).

1 Code Block
DATA STEP Data
Explanation :
Generation of source table 'x' with 3 iterations (i from 0 to 2).
Copied!
1DATA x ;
2 DO i=0 to 2 ;
3 j=round(uniform(i)*10) ;
4 put _all_ ;
5 OUTPUT ;
6 END ;
7RUN ;
2 Code Block
DATA STEP Data
Explanation :
Generation of lookup table 'y' with immediate creation of an index on variable 'i'.
Copied!
1DATA y(index=(i)) ;
2 DO i=1 to 4 ;
3 j=round(ranuni(i)*3) ;
4 DO k=1 to j ;
5 put _all_ ;
6 OUTPUT ;
7 END ;
8 END ;
9RUN ;
3 Code Block
DATA STEP Data
Explanation :
DATA step reading 'x' sequentially and accessing 'y' via index 'i' (KEY=i). Displaying _IORC_ allows checking for index lookup success.
Copied!
1DATA z ;
2 SET x(in=in_x) ;
3 SET y(in=in_y) key=i ;
4 put _iorc_= _all_ / ;
5RUN ;
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.