Interview Questions   Tutorials   Discussions   Programs   Videos   

SAS - What is the need of INDEX in datasets?

asked mar September 20, 2014 06:29 AM  

What is the need of INDEX in datasets?


1 Answers

answered By vishnoiprem   0  

Indexes are an alternative to sorting your dataset or building a format. They speed up any where or by processing.

Creating indexes

You can create an index in a data step like this:

data clm2 (index=(mbrno empssn mi=(mbrno iyymm) ei=(empssn iyymm))); set clm1; run;

The mi and ei are compound indexes, which behave as if you sorted your dataset mbrno iyymm or by empssn iyymm. You can use proc datasets to add an index to a dataset that already exists:

proc datasets library=saslib;
    modify clm2;
    index create mbrno empssn mi=(mbrno iyymm) ei=(empssn iyymm);
Using indexes

Indexes allow you to merge datasets that aren’t sorted. In the above example, now you can use clm2 just like it was sorted by any of the indexed vars:

data clmpluselig; merge clm2 mem; by empssn iyymm; run; This is another example of how to do a lookup.

data d1; infile datalines; input col1 8.; datalines; 101 106 102 102 103 103 104 105 ;

data d2 (index=(col1)); infile datalines; input col1 col2 $8.; datalines; 104 ddd 102 bbb 103 ccc 101 aaa ; data d3; set d1; set d2 key=col1 / unique;

/* This block handles bad lookups. */
if _IORC_ eq %sysrc(_DSENOM) then do;
    col2 = "xxx";


proc print heading=h data=d3;
   add comment

Your answer

Join with account you already have



 Write A Tutorials
Online-Classroom Classes

  1 person following this question

  Question tags

sas × 1

Asked 2 years and 3 months ago ago
Number of Views -259
Number of Answers -1
Last updated
3 years and 2 months ago ago

  Similar questions

Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!