BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yadaw
Fluorite | Level 6

Hi All,

 

I have a DATA SET called FR that has variables like: stu_id, name, age, gender. I want to create a simple index on stu_id using DATA step (Yes, we can do the same by PROC SQL or PROC DATASETS but here I want to create using DATA step).

I have written the below program but unable to create index:

DATA FR1 (INDEX=(stu_id=(stu_id)));

       SET FR;

RUN;

 

Can anybody help me on this?

And also, Is there any way to DELETE the created index by DATA step (I don't want to DELETE using PROC SQL or PROC DATASETS) ?

 

Thank You,

Yadaw

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

I could build an index, but don't know how to delete it yet.

 

data class(index=(name));
 set sashelp.class;
run;
proc contents data=class;
run;

Composite index.

data class(index=(comp=(name age)));
 set sashelp.class;
run;
proc contents data=class;
run;

View solution in original post

5 REPLIES 5
yadaw
Fluorite | Level 6

Hi All,

 

I have a DATA SET called FR that has variables like: stu_id, name, age, gender. I want to create a simple index on stu_id using DATA step (Yes, we can do the same by PROC SQL or PROC DATASETS but here I want to create using DATA step).

I have written the below program but unable to create index:

DATA FR1 (INDEX=(stu_id=(stu_id)));

       SET FR;

RUN;

 

Can anybody help me on this?

And also, Is there any way to DELETE the created index by DATA step (I don't want to DELETE using PROC SQL or PROC DATASETS) ?

 

Thank You,

Yadaw

Ksharp
Super User

I could build an index, but don't know how to delete it yet.

 

data class(index=(name));
 set sashelp.class;
run;
proc contents data=class;
run;

Composite index.

data class(index=(comp=(name age)));
 set sashelp.class;
run;
proc contents data=class;
run;
Ksharp
Super User
You could just simple copy the table to eliminate the index.

data x;
set class;
run;
proc contents data=x;
run;
RichardDeVen
Barite | Level 11

A data set index can be created in different ways

  • As specified by an output data set with option INDEX=
    • Simple indices (single columns) can not be named something else
    • Compound indices are specified <index-name>=(<column1> ... <column-n>)
  • PROC DATASETS; MODIFY
  • PROC SQL; CREATE INDEX

Index management is done with either DATASETS or SQL.  Read the documentation for more information about uniqueness and non-null indices and other data index topics such as integrity constraints and foreign keys.

 

Examples:

data cars(index=(Make Model type_drive=(Type DriveTrain)));
  set sashelp.cars;
run;

proc datasets nolist lib=work; 
  modify cars;
  index delete Make Model;
  index create Origin;
run;

proc sql;
  create index Make on work.cars;
  drop index type_drive from work.cars;
  create index type_cyl on work.cars(Type, Cylinders) ;

NOTE: SAS data sets do not have RDBMS features such as triggers or sequence numbers.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 779 views
  • 3 likes
  • 4 in conversation